其实只有一句话
EasyExcel.write(filePath, FbankTransactionDownloadDetail.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet(sheetName).doWrite(newDataList);
简单一点还可以这样
EasyExcel.write(filePath, FbankTransactionDownloadDetail.class).sheet(sheetName).doWrite(newDataList);
1.write方法源码是:
ExcelWriterBuilder write(String pathName, Class head)
pathName:是指filepath+filename
head:是class类
2.sheet方法源码是:
ExcelWriterSheetBuilder sheet(String sheetName) 用来设置sheet名
3.doWrite方法源码是
doWrite(List data) 指查询数据库的List对象
通过这单个方法就能写excel了.
值得注意的是:
1.data数据转义要先转好,code,status之类的要先转好中文
2.head的对象的字段要添加@ExcelProperty注解,index表示第几列,value是head名称.例如
@ExcelProperty(index = 0 ,value = "账户号")