模板
模板放在项目中的位置:template/excel/certificateTemplate.xlsx
代码
@Test
public void test06() throws IOException {
File rootPath = new File(ResourceUtils.getURL("classpath:").getPath());
File templatePath = new File(rootPath.getAbsolutePath(), "template/excel/certificateTemplate.xlsx");
String outsFileName = "预付款凭证-" + System.currentTimeMillis() + ".xlsx";
String modelFileName = "tempFile.xlsx";
File outModelFile = new File(modelFileName);
File outsFile = new File(rootPath + "/" + outsFileName);
String name = "张三1,张三2";
List<String> taskNoList = Arrays.asList(name.split(","));
EasyExcelUtil.createModel(taskNoList, outModelFile, templatePath);
ExcelWriter excelWriter = EasyExcel.write(outsFile).withTemplate(outModelFile).build();
// ExcelWriter excelWriter = EasyExcelUtil.setStyle(outModelFile, outsFile);
for (String taskNo : taskNoList) {
WriteSheet writeSheet = EasyExcel.writerSheet(taskNo).build();
FillData stocktakeTaskVo = getInfo(taskNo);
if (stocktakeTaskVo != null) {
Map<String, Object> map = MapUtils.newHashMap();
map.put("nowDate", Dat