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 0000000000000000000000000000000000000000..4c1b0d94d8602441f43bbf81ce26f01fed9ff3e9
GIT binary patch
literal 2397
zcma)6Yf~F#7(JWpW^-8}O(76V6%=iNr13&a%T1-B7EAyEsjaqlNm3FT5)2!sU;N}3
z|APJi`O+D6hNh0rIQpf|_?xWtJiD6!A=By1&U<;@=W^b2o_+uM@3%hyOkg*N0b~M*
zAS=VN3@bWTgV2!i;}eXOWc!{
zDXT3VIR$FP+$|`GWOmH2%~aW}Y^T<(TB))jjB~F?JJ08s}3feYz;~eDe>$(Tdrfc0Ya}ToSo=r6Sz?R#eGb;-M
zhWLu+e$mm2ye+cU>e^y=+ePUm
z1FvDoKn$-KIEO(4=kcn7{`NMTub0YsxnXxRIxe@IHIPTaz+1S$%O{4M;PC3;)?p@fmgKUu(9G^(nY=am0AA^>z*6p83&sBH#%o=Ie;_0-=7tY&98`Vs;
zvOQn2*lyCPOBm(@Fu<3^3y;Xbl}8k@XNtl(1Vz;1ILuv&v%*;$djjPb+wFCZKHKQW
z8(bTX14i&BcZ$fw@nrBJJU_PuhdKsR(pIp?Nj!E4?@w*PM#o@k-wJNRK7`s{xvOJv
z0!eZqu%|eCIQz!NAH&o6(ox65y|fS_Y$~|OI8EUu%uNb!w^DjZxum@C7~YpnDZ;c;
zp0iWFgLhjgkD*jwHl=9XN_pN+$$x|x7))ROffE@P6M^dW~U>~9ZGHgJ_TFJGEvw#p>$ag*##bEV-9
zf2J9(e3)haVFY#mzv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