easyExcel导出时动态生成sheet

假如我们最多有a-h八个sheet页需要动态生成(传一个生成一个sheet,传三个生成三个)

 

因为 new  sheet时需要给sheet编号,所以我们初始化一个index默认为1,

for (String s : typeList) {
                        if ("aaa".equals(s)){
                            Sheet sheet1 = new Sheet(index,0,new ExportAaaa().getClass());
                            sheet1.setSheetName("AAA");
                            sheet1.setAutoWidth(true);
                            List<ExportAaaa> list = new ArrayList<>();
                            list.add();//添加数据
                            writer.write(list, sheet1);
                            index ++;
                        }

上边最重要的就是ExportAaaa这个类,其实就是设置导出excel的表头


@Data
@ColumnWidth(25)
public class ExportFormation extends BaseRowModel {

    @ExcelProperty(value = "AAA",index = 0)
    private String AAAA;
    @ExcelProperty(value = "BBBB",index = 1)
    private Double BBBB;
    @ExcelProperty(value = "CCCC",index = 2)
    private Double CCCC;

}

 然后就是处理数据添加到list,我的做法是直接下载到浏览器的

发布了46 篇原创文章 · 获赞 4 · 访问量 5024

猜你喜欢

转载自blog.csdn.net/qq_35862393/article/details/103155840