1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| @Test public void exportExcel() { String filePath = Thread.currentThread().getContextClassLoader().getResource("list.xlsx").getPath(); String outPath = "./output.xlsx"; List<FillData> list = new ArrayList(); for (int i = 0; i < 10; i++) { FillData fillData = new FillData(); fillData.setName("张三"); fillData.setNumber(5.2); fillData.setDate(new Date()); list.add(fillData); } try (ExcelWriter excelWriter = EasyExcel.write(outPath).withTemplate(filePath).build()) { WriteSheet writeSheet = EasyExcel.writerSheet().build(); excelWriter.fill(list, writeSheet); }
}
|