Excel生成 ExcelWriter
1.Hutool将Excel写出封装为ExcelWriter,原理为包装了Workbook对象,每次调用merge(合并单元格)或者write(写出数据)方法后只是将数据写入到Workbook,并不写出文件,只有调用flush或者close方法后才会真正写出文件。
2.由于机制原因,在写出结束后需要关闭ExcelWriter对象,调用close方法即可关闭,此时才会释放Workbook对象资源,否则带有数据的Workbook一直会常驻内存。
将行列对象写出到Excel
先定义一个嵌套的List list的元素也是一个list 内层的一个list代表一行数据,每行都有四个单元格,最终list对象代多行数据。
List<String> rows1 = CollUtil.newArrayList("aa0","bb0","cc0","dd0");
List<String> rows2 = CollUtil.newArrayList("aa1","bb1","cc1","dd1");
List<String> rows3 = CollUtil.newArrayList("aa2","bb2","cc2","dd2");
List<String> rows4 = CollUtil.newArrayList("aa3","bb3","cc3","dd3");
List<String> rows5 = CollUtil.newArrayList("aa4","bb4","cc4","dd4");
List<List<String>> rows = CollUtil.newArrayList(row1,row2,row3,</