File templateFile = new File(filePath, fileName);
        File destFile = new File(filePath, "test.xlsx");
        try {
            if (templateFile.exists()) {
                //追加数据,目标文件与原始文件不能是同一个文件名
                //withTemplate()指定模板文件
                excelWriter = EasyExcel.write().withTemplate(templateFile)
                    	//.file() 指定目标文件,不能与模板文件是同一个文件
                        .file(destFile).autoCloseStream(false).build();
            } else {
                excelWriter = EasyExcel.write(templateFile, ElemPersonListExcel.class)
                        .build();
            }
            WriteSheet writeSheet = EasyExcel.writerSheet("人员清单")
                    .build();
            excelWriter.write(elemPersonListExcelList, writeSheet);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }

        if (destFile.exists()) {
            //删除原模板文件,新生成的文件变成新的模板文件
            templateFile.delete();
            destFile.renameTo(templateFile);
        }```

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-06-04
  • 2021-08-22
  • 2022-12-23
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-06-12
  • 2022-02-21
相关资源
相似解决方案