map = MapUtils.newHashMap();
+ map.put("date", "2019年10月9日13:28:28");
+ map.put("total", 1000);
+ excelWriter.fill(map, writeSheet);
+ }
+ }
+
+ /**
+ * 数据量大的复杂填充
+ *
+ * 这里的解决方案是 确保模板list为最后一行,然后再拼接table.还有03版没救,只能刚正面加内存。
+ *
+ * @since 2.1.1
+ */
+ @Test
+ public void complexFillWithTable() {
+ // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
+ // {} 代表普通变量 {.} 代表是list的变量
+ // 这里模板 删除了list以后的数据,也就是统计的这一行
+ String templateFileName =
+ TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx";
+
+ String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx";
+
+ // 方案1
+ try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) {
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
+ // 直接写入数据
+ excelWriter.fill(data(), writeSheet);
+ excelWriter.fill(data(), writeSheet);
+
+ // 写入list之前的数据
+ Map map = new HashMap();
+ map.put("date", "2019年10月9日13:28:28");
+ excelWriter.fill(map, writeSheet);
+
+ // list 后面还有个统计 想办法手动写入
+ // 这里偷懒直接用list 也可以用对象
+ List> totalListList = ListUtils.newArrayList();
+ List totalList = ListUtils.newArrayList();
+ totalListList.add(totalList);
+ totalList.add(null);
+ totalList.add(null);
+ totalList.add(null);
+ // 第四列
+ totalList.add("统计:1000");
+ // 这里是write 别和fill 搞错了
+ excelWriter.write(totalListList, writeSheet);
+ // 总体上写法比较复杂 但是也没有想到好的版本 异步的去写入excel 不支持行的删除和移动,也不支持备注这种的写入,所以也排除了可以
+ // 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案
+ }
+ }
+
+ /**
+ * 横向的填充
+ *
+ * @since 2.1.1
+ */
+ @Test
+ public void horizontalFill() {
+ // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
+ // {} 代表普通变量 {.} 代表是list的变量
+ String templateFileName =
+ TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "horizontal.xlsx";
+
+ String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx";
+ // 方案1
+ try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) {
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
+ FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
+ excelWriter.fill(data(), fillConfig, writeSheet);
+ excelWriter.fill(data(), fillConfig, writeSheet);
+
+ Map map = new HashMap<>();
+ map.put("date", "2019年10月9日13:28:28");
+ excelWriter.fill(map, writeSheet);
+ }
+ }
+
+ /**
+ * 多列表组合填充填充
+ *
+ * @since 2.2.0-beta1
+ */
+ @Test
+ public void compositeFill() {
+ // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
+ // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
+ String templateFileName =
+ TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "composite.xlsx";
+
+ String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx";
+
+ // 方案1
+ try (ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build()) {
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
+ FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.HORIZONTAL).build();
+ // 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹
+ excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet);
+ excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet);
+ excelWriter.fill(new FillWrapper("data2", data()), writeSheet);
+ excelWriter.fill(new FillWrapper("data2", data()), writeSheet);
+ excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
+ excelWriter.fill(new FillWrapper("data3", data()), writeSheet);
+
+ Map map = new HashMap();
+ //map.put("date", "2019年10月9日13:28:28");
+ map.put("date", new Date());
+
+ excelWriter.fill(map, writeSheet);
+ }
+ }
+
+ private List data() {
+ List list = ListUtils.newArrayList();
+ for (int i = 0; i < 10; i++) {
+ FillData fillData = new FillData();
+ list.add(fillData);
+ fillData.setName("张三");
+ fillData.setNumber(5.2);
+ fillData.setDate(new Date());
+ }
+ return list;
+ }
+}
diff --git a/src/main/java/org/nl/util/TestFileUtil.java b/src/main/java/org/nl/util/TestFileUtil.java
new file mode 100644
index 0000000..67e2b91
--- /dev/null
+++ b/src/main/java/org/nl/util/TestFileUtil.java
@@ -0,0 +1,74 @@
+package org.nl.util;
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestFileUtil {
+ public static InputStream getResourcesFileInputStream(String fileName) {
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
+ }
+
+ public static String getPath() {
+ return TestFileUtil.class.getResource("/").getPath();
+ }
+
+ public static TestPathBuild pathBuild() {
+ return new TestPathBuild();
+ }
+
+ public static File createNewFile(String pathName) {
+ File file = new File(getPath() + pathName);
+ if (file.exists()) {
+ file.delete();
+ } else {
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ }
+ return file;
+ }
+
+ public static File readFile(String pathName) {
+ return new File(getPath() + pathName);
+ }
+
+ public static File readUserHomeFile(String pathName) {
+ return new File(System.getProperty("user.home") + File.separator + pathName);
+ }
+
+ /**
+ * build to test file path
+ **/
+ public static class TestPathBuild {
+ private TestPathBuild() {
+ subPath = new ArrayList<>();
+ }
+
+ private final List subPath;
+
+ public TestPathBuild sub(String dirOrFile) {
+ subPath.add(dirOrFile);
+ return this;
+ }
+
+ public String getPath() {
+ if (CollectionUtils.isEmpty(subPath)) {
+ return TestFileUtil.class.getResource("/").getPath();
+ }
+ if (subPath.size() == 1) {
+ return TestFileUtil.class.getResource("/").getPath() + subPath.get(0);
+ }
+ StringBuilder path = new StringBuilder(TestFileUtil.class.getResource("/").getPath());
+ path.append(subPath.get(0));
+ for (int i = 1; i < subPath.size(); i++) {
+ path.append(File.separator).append(subPath.get(i));
+ }
+ return path.toString();
+ }
+
+ }
+}
diff --git a/target/classes/org/nl/fill/FillData.class b/target/classes/org/nl/fill/FillData.class
new file mode 100644
index 0000000..4c1b0d9
Binary files /dev/null and b/target/classes/org/nl/fill/FillData.class differ
diff --git a/target/classes/org/nl/fill/FillTest.class b/target/classes/org/nl/fill/FillTest.class
new file mode 100644
index 0000000..96307f5
Binary files /dev/null and b/target/classes/org/nl/fill/FillTest.class differ
diff --git a/target/classes/org/nl/util/TestFileUtil$1.class b/target/classes/org/nl/util/TestFileUtil$1.class
new file mode 100644
index 0000000..d7c3ce8
Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil$1.class differ
diff --git a/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class b/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class
new file mode 100644
index 0000000..5854fa2
Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil$TestPathBuild.class differ
diff --git a/target/classes/org/nl/util/TestFileUtil.class b/target/classes/org/nl/util/TestFileUtil.class
new file mode 100644
index 0000000..2740462
Binary files /dev/null and b/target/classes/org/nl/util/TestFileUtil.class differ
diff --git a/target/classes/simpleFill1731491705207.xlsx b/target/classes/simpleFill1731491705207.xlsx
new file mode 100644
index 0000000..e69de29