From 3b36f82d24b0fb6adee9f1212b9d4459aacd7ef2 Mon Sep 17 00:00:00 2001 From: weiwensangsang Date: Mon, 28 Oct 2019 17:46:54 +0800 Subject: [PATCH 01/17] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index fd5c5a2f..67933f53 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,22 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都 ## 维护者 玉霄、庄家钜、怀宇 ## 快速开始 +### 引入项目 +Maven +```java + + + com.alibaba + easyexcel + 2.1.0-beta4 + +``` +Gradle +```java +// https://mvnrepository.com/artifact/com.alibaba/easyexcel +compile group: 'com.alibaba', name: 'easyexcel', version: '2.1.0-beta4' +``` + ### 读Excel DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/demo/read/ReadTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java) From 726a5636933cccf883f6aecd350146a460669dfb Mon Sep 17 00:00:00 2001 From: weiwensangsang Date: Sat, 2 Nov 2019 16:44:15 +0800 Subject: [PATCH 02/17] Revert "Update README.md" This reverts commit 3b36f82d24b0fb6adee9f1212b9d4459aacd7ef2. --- README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/README.md b/README.md index 67933f53..fd5c5a2f 100644 --- a/README.md +++ b/README.md @@ -23,22 +23,6 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都 ## 维护者 玉霄、庄家钜、怀宇 ## 快速开始 -### 引入项目 -Maven -```java - - - com.alibaba - easyexcel - 2.1.0-beta4 - -``` -Gradle -```java -// https://mvnrepository.com/artifact/com.alibaba/easyexcel -compile group: 'com.alibaba', name: 'easyexcel', version: '2.1.0-beta4' -``` - ### 读Excel DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/demo/read/ReadTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java) From 07c79a558d28cde4e469a8f34d3ffaad23cc7277 Mon Sep 17 00:00:00 2001 From: weiwensangsang Date: Sat, 2 Nov 2019 21:36:24 +0800 Subject: [PATCH 03/17] Update PoiWriteTest.java --- .../com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java index 3a70d0d4..1586d1cc 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java @@ -7,6 +7,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.regex.Pattern; +import com.alibaba.fastjson.util.ParameterizedTypeImpl; import org.apache.poi.ss.formula.functions.T; import org.apache.poi.xssf.streaming.SXSSFCell; import org.apache.poi.xssf.streaming.SXSSFRow; @@ -20,7 +21,6 @@ import org.slf4j.LoggerFactory; import com.alibaba.excel.metadata.CellData; import com.alibaba.fastjson.JSON; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; /** * 测试poi @@ -118,7 +118,7 @@ public class PoiWriteTest { Type[] tArgs = pType.getActualTypeArguments(); // 获得泛型类型的泛型参数(实际类型参数) ParameterizedTypeImpl c = (ParameterizedTypeImpl)pType.getActualTypeArguments()[0]; - Class ttt = c.getRawType(); + Class ttt = c.getClass(); System.out.println(ttt); } else { System.out.println("出错!!!"); @@ -145,7 +145,7 @@ public class PoiWriteTest { Type[] tArgs = pType.getActualTypeArguments(); // 获得泛型类型的泛型参数(实际类型参数) ParameterizedTypeImpl c = (ParameterizedTypeImpl)pType.getActualTypeArguments()[0]; - Class ttt = c.getRawType(); + Class ttt = c.getClass(); System.out.println(ttt); } else { System.out.println("出错!!!"); From 909a44605ce8a0c1b619ab998cf6d0178aad7151 Mon Sep 17 00:00:00 2001 From: weiwensangsang Date: Tue, 5 Nov 2019 17:51:32 +0800 Subject: [PATCH 04/17] Revert "Update PoiWriteTest.java" This reverts commit 07c79a558d28cde4e469a8f34d3ffaad23cc7277. --- .../com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java index 1586d1cc..3a70d0d4 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiWriteTest.java @@ -7,7 +7,6 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.regex.Pattern; -import com.alibaba.fastjson.util.ParameterizedTypeImpl; import org.apache.poi.ss.formula.functions.T; import org.apache.poi.xssf.streaming.SXSSFCell; import org.apache.poi.xssf.streaming.SXSSFRow; @@ -21,6 +20,7 @@ import org.slf4j.LoggerFactory; import com.alibaba.excel.metadata.CellData; import com.alibaba.fastjson.JSON; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; /** * 测试poi @@ -118,7 +118,7 @@ public class PoiWriteTest { Type[] tArgs = pType.getActualTypeArguments(); // 获得泛型类型的泛型参数(实际类型参数) ParameterizedTypeImpl c = (ParameterizedTypeImpl)pType.getActualTypeArguments()[0]; - Class ttt = c.getClass(); + Class ttt = c.getRawType(); System.out.println(ttt); } else { System.out.println("出错!!!"); @@ -145,7 +145,7 @@ public class PoiWriteTest { Type[] tArgs = pType.getActualTypeArguments(); // 获得泛型类型的泛型参数(实际类型参数) ParameterizedTypeImpl c = (ParameterizedTypeImpl)pType.getActualTypeArguments()[0]; - Class ttt = c.getClass(); + Class ttt = c.getRawType(); System.out.println(ttt); } else { System.out.println("出错!!!"); From faa22d734f298e19e412e2a5064dadb67fee51b7 Mon Sep 17 00:00:00 2001 From: pdkst Date: Sat, 9 Nov 2019 00:02:35 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B7=BB=E5=8A=A0sheet?= =?UTF-8?q?=E9=A1=B5=E5=89=8D=E7=9A=84null=E6=A0=A1=E9=AA=8C=EF=BC=8Cwrite?= =?UTF-8?q?(null)=E6=97=B6=E4=B9=9F=E4=BC=9A=E8=BE=93=E5=87=BA=E8=A1=A8?= =?UTF-8?q?=E5=A4=B4=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java index 59f78bfb..e118db4e 100644 --- a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java +++ b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java @@ -50,9 +50,6 @@ public class ExcelBuilderImpl implements ExcelBuilder { @Override public void addContent(List data, WriteSheet writeSheet, WriteTable writeTable) { try { - if (data == null) { - return; - } context.currentSheet(writeSheet, WriteTypeEnum.ADD); context.currentTable(writeTable); if (excelWriteAddExecutor == null) { @@ -105,9 +102,6 @@ public class ExcelBuilderImpl implements ExcelBuilder { @Override public void addContent(List data, WriteSheet writeSheet, WriteTable writeTable, String password) { try { - if (data == null) { - return; - } context.currentSheet(writeSheet, WriteTypeEnum.ADD); context.currentTable(writeTable); if (excelWriteAddExecutor == null) { From af2c3882624d0451f08b5a9c7ed0e74ab5343594 Mon Sep 17 00:00:00 2001 From: zl Date: Wed, 20 Nov 2019 18:31:19 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E5=8E=BB=E6=8E=89LongestMatchColumnWidth?= =?UTF-8?q?StyleStrategy=E7=BC=93=E5=AD=98=E7=9A=84static=E4=BF=AE?= =?UTF-8?q?=E9=A5=B0=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../style/column/LongestMatchColumnWidthStyleStrategy.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java index 5140ae68..38a6dbb2 100644 --- a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java @@ -24,7 +24,7 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty private static final int MAX_COLUMN_WIDTH = 255; - private static final Map> CACHE = new HashMap>(8); + private final Map> cache = new HashMap>(8); @Override protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List cellDataList, Cell cell, Head head, @@ -33,10 +33,10 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty if (!needSetWidth) { return; } - Map maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo()); + Map maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo()); if (maxColumnWidthMap == null) { maxColumnWidthMap = new HashMap(16); - CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); + cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); } Integer columnWidth = dataLength(cellDataList, cell, isHead); if (columnWidth < 0) { From 1845b6b0a17a033b41edf9bedca3b10e54eaa6e9 Mon Sep 17 00:00:00 2001 From: dota17 Date: Thu, 27 Feb 2020 09:30:25 +0800 Subject: [PATCH 07/17] fix some typos --- .../{NoModleDataListener.java => NoModelDataListener.java} | 6 +++--- .../java/com/alibaba/easyexcel/test/demo/read/ReadTest.java | 4 ++-- .../com/alibaba/easyexcel/test/demo/write/WriteTest.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/test/java/com/alibaba/easyexcel/test/demo/read/{NoModleDataListener.java => NoModelDataListener.java} (92%) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModleDataListener.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java similarity index 92% rename from src/test/java/com/alibaba/easyexcel/test/demo/read/NoModleDataListener.java rename to src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java index 2e775387..ea47c236 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModleDataListener.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java @@ -16,8 +16,8 @@ import com.alibaba.fastjson.JSON; * * @author Jiaju Zhuang */ -public class NoModleDataListener extends AnalysisEventListener> { - private static final Logger LOGGER = LoggerFactory.getLogger(NoModleDataListener.class); +public class NoModelDataListener extends AnalysisEventListener> { + private static final Logger LOGGER = LoggerFactory.getLogger(NoModelDataListener.class); /** * 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收 */ @@ -40,7 +40,7 @@ public class NoModleDataListener extends AnalysisEventListener Date: Thu, 27 Feb 2020 09:43:53 +0800 Subject: [PATCH 08/17] fix a typo --- .../alibaba/easyexcel/test/demo/read/NoModelDataListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java index ea47c236..a48d3fca 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/NoModelDataListener.java @@ -40,7 +40,7 @@ public class NoModelDataListener extends AnalysisEventListener Date: Thu, 27 Feb 2020 21:47:30 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BD=93Data=E6=98=AFL?= =?UTF-8?q?inkedList=E6=97=B6=EF=BC=8C=E9=9A=8F=E7=9D=80=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=87=8F=E5=A2=9E=E5=8A=A0=E6=80=A7=E8=83=BD=E5=8F=98=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 入参为List,当List是LinkedList时,get方法性能很差 --- .../alibaba/excel/write/executor/ExcelWriteAddExecutor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 5b0d8ae8..a572fb72 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -46,9 +46,11 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } // BeanMap is out of order,so use fieldList List fieldList = new ArrayList(); - for (int relativeRowIndex = 0; relativeRowIndex < data.size(); relativeRowIndex++) { + int relativeRowIndex=0; + for(Object oneRowData : data){ int n = relativeRowIndex + newRowIndex; - addOneRowOfDataToExcel(data.get(relativeRowIndex), n, relativeRowIndex, fieldList); + addOneRowOfDataToExcel(oneRowData, n, relativeRowIndex, fieldList); + relativeRowIndex++; } } From 487c18a7881c27a558b035e3fd5fb4df6a098324 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 17 Mar 2020 22:00:42 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E6=96=B0=E5=A2=9Esince?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/easyexcel/test/demo/read/ReadTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java index 5234f052..b411cae3 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java @@ -173,6 +173,8 @@ public class ReadTest { * 2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoExtraListener} *

* 3. 直接读即可 + * + * @since 2.2.0-beat1 */ @Test public void extraRead() { @@ -191,11 +193,13 @@ public class ReadTest { * 读取公式和单元格类型 * *

- * 1. 创建excel对应的实体对象 参照{@link DemoData} + * 1. 创建excel对应的实体对象 参照{@link CellDataReadDemoData} *

* 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoHeadDataListener} *

* 3. 直接读即可 + * + * @since 2.2.0-beat1 */ @Test public void cellDataRead() { From 254387d0f8f3859a9eb06aae5fc49a72a775353c Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 17 Mar 2020 22:22:59 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E6=96=B0=E5=A2=9Esince?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/easyexcel/test/demo/fill/FillTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java index 068045e8..48fd9f1f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java @@ -181,7 +181,7 @@ public class FillTest { } /** - * 组合填充填充 + * 多列表组合填充填充 * * @since 2.2.0 */ From 3ef7c198d8cbb928db6d54796e94eddd2592ec31 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 17 Mar 2020 22:23:15 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E6=96=B0=E5=A2=9Esince?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/easyexcel/test/demo/fill/FillTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java index 48fd9f1f..7a0e92e5 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java @@ -183,7 +183,7 @@ public class FillTest { /** * 多列表组合填充填充 * - * @since 2.2.0 + * @since 2.2.0-beta1 */ @Test public void compositeFill() { From d44523d1426e42a790be2eb10b696684048fe7ea Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 17 Mar 2020 23:17:54 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=80=E9=95=BF?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E7=AD=96=E7=95=A5=E4=B8=8D=E5=90=8C=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E4=BC=9A=E6=9C=89=E5=BD=B1=E5=93=8D=E7=9A=84bug=20#10?= =?UTF-8?q?10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../style/column/LongestMatchColumnWidthStyleStrategy.java | 6 +++--- update.md | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 4a47b3da..51f63232 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 2.2.0-beta1 + 2.2.0-beta2 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java index 5140ae68..cc8dcb20 100644 --- a/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java +++ b/src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java @@ -24,7 +24,7 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty private static final int MAX_COLUMN_WIDTH = 255; - private static final Map> CACHE = new HashMap>(8); + private Map> cache = new HashMap>(8); @Override protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List cellDataList, Cell cell, Head head, @@ -33,10 +33,10 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty if (!needSetWidth) { return; } - Map maxColumnWidthMap = CACHE.get(writeSheetHolder.getSheetNo()); + Map maxColumnWidthMap = cache.get(writeSheetHolder.getSheetNo()); if (maxColumnWidthMap == null) { maxColumnWidthMap = new HashMap(16); - CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); + cache.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap); } Integer columnWidth = dataLength(cellDataList, cell, isHead); if (columnWidth < 0) { diff --git a/update.md b/update.md index 834bee6b..0f680323 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,6 @@ +# 2.2.0-beta1 +* 修复最长匹配策略不同表格会有影响的bug [Issue #1010](https://github.com/alibaba/easyexcel/issues/1010) + # 2.2.0-beta1 * 重写主流程,代码更加优雅 * 修复用String接收日期、数字和excel显示不一致的bug(不是完美修复,但是大部分情况已经兼容) From 04883601ed7dc1c74ab85c7397b74f5817ea2f0e Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 18 Mar 2020 00:00:21 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E6=96=B0=E5=A2=9Esince?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/easyexcel/test/demo/write/WriteTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index 0a04f896..43c6e683 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java @@ -275,6 +275,8 @@ public class WriteTest { * 1. 创建excel对应的实体对象 参照{@link DemoStyleData} *

* 3. 直接写即可 + * + * @since 2.2.0-beta1 */ @Test public void annotationStyleWrite() { @@ -329,6 +331,8 @@ public class WriteTest { * 2. 创建一个merge策略 并注册 *

* 3. 直接写即可 + * + * @since 2.2.0-beta1 */ @Test public void mergeWrite() { From 0cb24f848a7a5ff1fcbec16d42abb5f08d7e29fa Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 18 Mar 2020 00:09:05 +0800 Subject: [PATCH 15/17] =?UTF-8?q?`LinkedList`=E5=86=99=E5=85=A5=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98=20#1121?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.md | 1 + 1 file changed, 1 insertion(+) diff --git a/update.md b/update.md index 0f680323..43dd5607 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,6 @@ # 2.2.0-beta1 * 修复最长匹配策略不同表格会有影响的bug [Issue #1010](https://github.com/alibaba/easyexcel/issues/1010) +* `LinkedList`写入的性能问题 #1121 # 2.2.0-beta1 * 重写主流程,代码更加优雅 From 3b7b6729aa5443ea2d3bc910da887bbd29dae9bf Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 18 Mar 2020 00:32:55 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E7=A7=BB=E9=99=A4password=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/excel/write/ExcelBuilder.java | 9 -------- .../alibaba/excel/write/ExcelBuilderImpl.java | 21 ------------------- 2 files changed, 30 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/ExcelBuilder.java b/src/main/java/com/alibaba/excel/write/ExcelBuilder.java index 4ef3b42a..d3a50e35 100644 --- a/src/main/java/com/alibaba/excel/write/ExcelBuilder.java +++ b/src/main/java/com/alibaba/excel/write/ExcelBuilder.java @@ -76,13 +76,4 @@ public interface ExcelBuilder { */ void finish(boolean onException); - /** - * add password - * - * @param data - * @param writeSheet - * @param writeTable - * @param password - */ - void addContent(List data, WriteSheet writeSheet, WriteTable writeTable, String password); } diff --git a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java index e118db4e..0c7158ed 100644 --- a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java +++ b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java @@ -68,9 +68,6 @@ public class ExcelBuilderImpl implements ExcelBuilder { @Override public void fill(Object data, FillConfig fillConfig, WriteSheet writeSheet) { try { - if (data == null) { - return; - } if (context.writeWorkbookHolder().getTempTemplateInputStream() == null) { throw new ExcelGenerateException("Calling the 'fill' method must use a template."); } @@ -99,24 +96,6 @@ public class ExcelBuilderImpl implements ExcelBuilder { } } - @Override - public void addContent(List data, WriteSheet writeSheet, WriteTable writeTable, String password) { - try { - context.currentSheet(writeSheet, WriteTypeEnum.ADD); - context.currentTable(writeTable); - if (excelWriteAddExecutor == null) { - excelWriteAddExecutor = new ExcelWriteAddExecutor(context); - } - excelWriteAddExecutor.add(data); - } catch (RuntimeException e) { - finishOnException(); - throw e; - } catch (Throwable e) { - finishOnException(); - throw new ExcelGenerateException(e); - } - } - @Override public void merge(int firstRow, int lastRow, int firstCol, int lastCol) { CellRangeAddress cra = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol); From da7b7879de8a5f8233139284bafdd9d06c42db91 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 23 Mar 2020 19:49:28 +0800 Subject: [PATCH 17/17] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E5=8F=AF=E8=83=BD=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84`warn`=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/excel/ExcelReader.java | 4 +- .../java/com/alibaba/excel/ExcelWriter.java | 4 +- .../test/demo/write/CommentWriteHandler.java | 37 +++++++++++++++++++ .../easyexcel/test/demo/write/WriteTest.java | 18 +++++++++ update.md | 3 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/write/CommentWriteHandler.java diff --git a/src/main/java/com/alibaba/excel/ExcelReader.java b/src/main/java/com/alibaba/excel/ExcelReader.java index 07a373b7..6cd0f782 100644 --- a/src/main/java/com/alibaba/excel/ExcelReader.java +++ b/src/main/java/com/alibaba/excel/ExcelReader.java @@ -274,7 +274,9 @@ public class ExcelReader { * Complete the entire read file.Release the cache and close stream. */ public void finish() { - excelAnalyser.finish(); + if (excelAnalyser != null) { + excelAnalyser.finish(); + } } /** diff --git a/src/main/java/com/alibaba/excel/ExcelWriter.java b/src/main/java/com/alibaba/excel/ExcelWriter.java index a0b4795b..0eafecde 100644 --- a/src/main/java/com/alibaba/excel/ExcelWriter.java +++ b/src/main/java/com/alibaba/excel/ExcelWriter.java @@ -325,7 +325,9 @@ public class ExcelWriter { * Close IO */ public void finish() { - excelBuilder.finish(false); + if (excelBuilder != null) { + excelBuilder.finish(false); + } } /** diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/CommentWriteHandler.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/CommentWriteHandler.java new file mode 100644 index 00000000..299d4072 --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/CommentWriteHandler.java @@ -0,0 +1,37 @@ +package com.alibaba.easyexcel.test.demo.write; + +import org.apache.poi.ss.usermodel.Comment; +import org.apache.poi.ss.usermodel.Drawing; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; +import org.apache.poi.xssf.usermodel.XSSFRichTextString; + +import com.alibaba.excel.write.handler.AbstractRowWriteHandler; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteTableHolder; + +/** + * 自定义拦截器.新增注释,第一行头加批注 + * + * @author Jiaju Zhuang + */ +public class CommentWriteHandler extends AbstractRowWriteHandler { + + @Override + public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, + Integer relativeRowIndex, Boolean isHead) { + if (isHead) { + Sheet sheet = writeSheetHolder.getSheet(); + Drawing drawingPatriarch = sheet.createDrawingPatriarch(); + // 在第一行 第二列创建一个批注 + Comment comment = + drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short)1, 0, (short)2, 1)); + // 输入批注信息 + comment.setString(new XSSFRichTextString("创建批注!")); + // 将批注添加到单元格对象中 + sheet.getRow(0).getCell(1).setCellComment(comment); + } + } + +} diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index c54ceb7f..7139fa8f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java @@ -439,6 +439,24 @@ public class WriteTest { .registerWriteHandler(new CustomCellWriteHandler()).sheet("模板").doWrite(data()); } + /** + * 插入批注 + *

+ * 1. 创建excel对应的实体对象 参照{@link DemoData} + *

+ * 2. 注册拦截器 {@link CommentWriteHandler} + *

+ * 2. 直接写即可 + */ + @Test + public void commentWrite() { + String fileName = TestFileUtil.getPath() + "commentWrite" + System.currentTimeMillis() + ".xlsx"; + // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 + // 这里要注意inMemory 要设置为true,才能支持批注。目前没有好的办法解决 不在内存处理批注。这个需要自己选择。 + EasyExcel.write(fileName, DemoData.class).inMemory(Boolean.TRUE).registerWriteHandler(new CommentWriteHandler()) + .sheet("模板").doWrite(data()); + } + /** * 可变标题处理(包括标题国际化等) *

diff --git a/update.md b/update.md index 43dd5607..b075a266 100644 --- a/update.md +++ b/update.md @@ -1,6 +1,7 @@ -# 2.2.0-beta1 +# 2.2.0-beta2 * 修复最长匹配策略不同表格会有影响的bug [Issue #1010](https://github.com/alibaba/easyexcel/issues/1010) * `LinkedList`写入的性能问题 #1121 +* 修复在某些情况下可能出现不必要的`warn`日志 # 2.2.0-beta1 * 重写主流程,代码更加优雅