获取静态模板
生成List 作为excel表体
生成map作为excel表尾
ClassPathResource classPathResource = new ClassPathResource("template/AlipayDetailTemplate.xlsx");
InputStream inputStream =null;
try {
inputStream = classPathResource.getInputStream();
} catch (IOException e) {
XxlJobLogger.log("获取账单明细模板失败!");
e.printStackTrace();
}
String templateFileName = "template/AlipayDetailTemplate.xlsx";
try { templateFileName = ResourceUtils.getFile("classpath:template/AlipayDetailTemplate.xlsx").getPath();
XxlJobLogger.log("模板地址:{}",templateFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
String templateFileName ="C:\\Users\\kunchi\\Desktop\\常用信息\\alipay\\AlipayDetailTemplate.xlsx";
OutputStream outputStream =null;
try {
outputStream =new FileOutputStream(fileName);
} catch (FileNotFoundException e) {
log.error("文件输出流生成失败,错误信息:{}"+e.getMessage());
}
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(inputStream).build();
try{
inputStream.close();
}catch (Exception e){
log.error("文件模板关闭失败"+e.getMessage());
}
XxlJobLogger.log("商户:{},获取模板成功!",authToken.getOtherName());
WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
excelWriter.fill(batchList, fillConfig, writeSheet);
代码很乱 请按需观看