From 88de089c1068cf4f92c4b419bf0bb8494e6c8f6f Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 2 Jan 2020 21:30:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A1=AB=E5=85=85=E6=97=B6=E5=80=99?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE`sheetName`=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D`sheet`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../v07/handlers/DefaultCellHandler.java | 6 +- .../handlers/ProcessResultCellHandler.java | 5 +- .../excel/context/WriteContextImpl.java | 68 +++++++++++------- .../com/alibaba/excel/util/PositionUtils.java | 25 +++++++ .../metadata/holder/WriteSheetHolder.java | 6 +- .../metadata/holder/WriteWorkbookHolder.java | 25 +++++-- .../test/core/fill/FillDataTest.java | 25 +++++++ src/test/resources/fill/byName.xls | Bin 0 -> 28160 bytes src/test/resources/fill/byName.xlsx | Bin 0 -> 11489 bytes update.md | 4 ++ 11 files changed, 126 insertions(+), 40 deletions(-) create mode 100644 src/test/resources/fill/byName.xls create mode 100644 src/test/resources/fill/byName.xlsx diff --git a/pom.xml b/pom.xml index 415b45a..844f70c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 2.1.4 + 2.1.5 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java index e0b9c41..e53c3cc 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java @@ -36,7 +36,7 @@ import com.alibaba.excel.util.PositionUtils; public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder { private final AnalysisContext analysisContext; private Deque currentTagDeque = new LinkedList(); - private int curCol; + private int curCol = -1; private Map curRowContent = new LinkedHashMap(); private CellData currentCellData; private StringBuilder dataStringBuilder; @@ -55,6 +55,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder @Override public void clearResult() { curRowContent = new LinkedHashMap(); + curCol=-1; } @Override @@ -68,7 +69,8 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder currentTagDeque.push(name); // start a cell if (CELL_TAG.equals(name)) { - curCol = PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.POSITION)); + curCol = PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.POSITION),curCol); + // t="s" ,it's means String // t="str" ,it's means String,but does not need to be read in the 'sharedStrings.xml' diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java index 9581646..c854242 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java @@ -20,6 +20,7 @@ import com.alibaba.excel.util.PositionUtils; public class ProcessResultCellHandler implements XlsxCellHandler { private AnalysisContext analysisContext; private XlsxRowResultHolder rowResultHandler; + private int currentRow = -1; public ProcessResultCellHandler(AnalysisContext analysisContext, XlsxRowResultHolder rowResultHandler) { this.analysisContext = analysisContext; @@ -33,9 +34,9 @@ public class ProcessResultCellHandler implements XlsxCellHandler { @Override public void startHandle(String name, Attributes attributes) { + currentRow = PositionUtils.getRowByRowTagt(attributes.getValue(ExcelXmlConstants.POSITION),currentRow); analysisContext.readRowHolder( - new ReadRowHolder(PositionUtils.getRowByRowTagt(attributes.getValue(ExcelXmlConstants.POSITION)), - analysisContext.readSheetHolder().getGlobalConfiguration())); + new ReadRowHolder(currentRow, analysisContext.readSheetHolder().getGlobalConfiguration())); } @Override diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index a07ad4c..890bef2 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -103,37 +103,44 @@ public class WriteContextImpl implements WriteContext { */ @Override public void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType) { - if (writeSheet == null) { - throw new IllegalArgumentException("Sheet argument cannot be null"); + boolean illegalArgument = + writeSheet == null || (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())); + if (illegalArgument) { + throw new IllegalArgumentException("Sheet name and Sheet number can not be empty."); } - if (writeSheet.getSheetNo() == null || writeSheet.getSheetNo() <= 0) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Sheet number is null"); - } - writeSheet.setSheetNo(0); - } - if (writeWorkbookHolder.getHasBeenInitializedSheet().containsKey(writeSheet.getSheetNo())) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Sheet:{} is already existed", writeSheet.getSheetNo()); - } - writeSheetHolder = writeWorkbookHolder.getHasBeenInitializedSheet().get(writeSheet.getSheetNo()); - writeSheetHolder.setNewInitialization(Boolean.FALSE); - writeTableHolder = null; - currentWriteHolder = writeSheetHolder; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("CurrentConfiguration is writeSheetHolder"); - } + if (selectSheetFromCache(writeSheet)) { return; } initCurrentSheetHolder(writeSheet); - WriteHandlerUtils.beforeSheetCreate(this); // Initialization current sheet initSheet(writeType); } + private boolean selectSheetFromCache(WriteSheet writeSheet) { + writeSheetHolder = null; + if (writeSheet.getSheetNo() != null) { + writeSheetHolder = writeWorkbookHolder.getHasBeenInitializedSheetIndexMap().get(writeSheet.getSheetNo()); + } + if (writeSheetHolder == null && !StringUtils.isEmpty(writeSheet.getSheetName())) { + writeSheetHolder = writeWorkbookHolder.getHasBeenInitializedSheetNameMap().get(writeSheet.getSheetName()); + } + if (writeSheetHolder == null) { + return false; + } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Sheet:{} is already existed", writeSheet.getSheetNo()); + } + writeSheetHolder.setNewInitialization(Boolean.FALSE); + writeTableHolder = null; + currentWriteHolder = writeSheetHolder; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("CurrentConfiguration is writeSheetHolder"); + } + return true; + } + private void initCurrentSheetHolder(WriteSheet writeSheet) { writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder); - writeWorkbookHolder.getHasBeenInitializedSheet().put(writeSheet.getSheetNo(), writeSheetHolder); writeTableHolder = null; currentWriteHolder = writeSheetHolder; if (LOGGER.isDebugEnabled()) { @@ -142,15 +149,26 @@ public class WriteContextImpl implements WriteContext { } private void initSheet(WriteTypeEnum writeType) { + WriteHandlerUtils.beforeSheetCreate(this); Sheet currentSheet; try { - currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo()); - writeSheetHolder - .setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo())); + if (writeSheetHolder.getSheetNo() != null) { + currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo()); + writeSheetHolder + .setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo())); + } else { + // sheet name must not null + currentSheet = writeWorkbookHolder.getWorkbook().getSheet(writeSheetHolder.getSheetName()); + writeSheetHolder + .setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheet(writeSheetHolder.getSheetName())); + } } catch (Exception e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Can not find sheet:{} ,now create it", writeSheetHolder.getSheetNo()); } + if (StringUtils.isEmpty(writeSheetHolder.getSheetName())) { + writeSheetHolder.setSheetName(writeSheetHolder.getSheetNo().toString()); + } currentSheet = WorkBookUtil.createSheet(writeWorkbookHolder.getWorkbook(), writeSheetHolder.getSheetName()); writeSheetHolder.setCachedSheet(currentSheet); } @@ -160,6 +178,8 @@ public class WriteContextImpl implements WriteContext { // Initialization head initHead(writeSheetHolder.excelWriteHeadProperty()); } + writeWorkbookHolder.getHasBeenInitializedSheetIndexMap().put(writeSheetHolder.getSheetNo(), writeSheetHolder); + writeWorkbookHolder.getHasBeenInitializedSheetNameMap().put(writeSheetHolder.getSheetName(), writeSheetHolder); } public void initHead(ExcelWriteHeadProperty excelWriteHeadProperty) { diff --git a/src/main/java/com/alibaba/excel/util/PositionUtils.java b/src/main/java/com/alibaba/excel/util/PositionUtils.java index f135e47..b85018f 100644 --- a/src/main/java/com/alibaba/excel/util/PositionUtils.java +++ b/src/main/java/com/alibaba/excel/util/PositionUtils.java @@ -14,6 +14,16 @@ public class PositionUtils { } return row; } + public static int getRowByRowTagt(String rowTagt,int before) { + int row ; + if (rowTagt != null) { + row = Integer.parseInt(rowTagt) - 1; + return row; + }else { + return before + 1; + } + + } public static int getRow(String currentCellIndex) { int row = 0; @@ -35,4 +45,19 @@ public class PositionUtils { } return col - 1; } + + public static int getCol(String currentCellIndex,int before) { + int col = 0; + if (currentCellIndex != null) { + + char[] currentIndex = currentCellIndex.replaceAll("[0-9]", "").toCharArray(); + for (int i = 0; i < currentIndex.length; i++) { + col += (currentIndex[i] - '@') * Math.pow(26, (currentIndex.length - i - 1)); + } + return col - 1; + }else { + return before +1; + } + } + } diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java index 90030f4..b74db29 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java @@ -68,11 +68,7 @@ public class WriteSheetHolder extends AbstractWriteHolder { super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); this.writeSheet = writeSheet; this.sheetNo = writeSheet.getSheetNo(); - if (writeSheet.getSheetName() == null) { - this.sheetName = writeSheet.getSheetNo().toString(); - } else { - this.sheetName = writeSheet.getSheetName(); - } + this.sheetName = writeSheet.getSheetName(); this.parentWriteWorkbookHolder = writeWorkbookHolder; this.hasBeenInitializedTable = new HashMap(); if (writeWorkbookHolder.getTempTemplateInputStream() != null) { diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java index c8f7555..be557eb 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java @@ -92,7 +92,11 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { /** * prevent duplicate creation of sheet objects */ - private Map hasBeenInitializedSheet; + private Map hasBeenInitializedSheetIndexMap; + /** + * prevent duplicate creation of sheet objects + */ + private Map hasBeenInitializedSheetNameMap; /** * Whether the encryption */ @@ -148,7 +152,8 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { } else { this.mandatoryUseInputStream = writeWorkbook.getMandatoryUseInputStream(); } - this.hasBeenInitializedSheet = new HashMap(); + this.hasBeenInitializedSheetIndexMap = new HashMap(); + this.hasBeenInitializedSheetNameMap = new HashMap(); this.password = writeWorkbook.getPassword(); if (writeWorkbook.getInMemory() == null) { this.inMemory = Boolean.FALSE; @@ -197,12 +202,20 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { this.cachedWorkbook = cachedWorkbook; } - public Map getHasBeenInitializedSheet() { - return hasBeenInitializedSheet; + public Map getHasBeenInitializedSheetIndexMap() { + return hasBeenInitializedSheetIndexMap; + } + + public void setHasBeenInitializedSheetIndexMap(Map hasBeenInitializedSheetIndexMap) { + this.hasBeenInitializedSheetIndexMap = hasBeenInitializedSheetIndexMap; + } + + public Map getHasBeenInitializedSheetNameMap() { + return hasBeenInitializedSheetNameMap; } - public void setHasBeenInitializedSheet(Map hasBeenInitializedSheet) { - this.hasBeenInitializedSheet = hasBeenInitializedSheet; + public void setHasBeenInitializedSheetNameMap(Map hasBeenInitializedSheetNameMap) { + this.hasBeenInitializedSheetNameMap = hasBeenInitializedSheetNameMap; } public WriteWorkbook getWriteWorkbook() { diff --git a/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java index 04a8bd1..fe02163 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java @@ -39,6 +39,10 @@ public class FillDataTest { private static File horizontalFillTemplate07; private static File fileHorizontal03; private static File horizontalFillTemplate03; + private static File byName07; + private static File byName03; + private static File byNameTemplate07; + private static File byNameTemplate03; @BeforeClass public static void init() { @@ -54,6 +58,10 @@ public class FillDataTest { horizontalFillTemplate07 = TestFileUtil.readFile("fill" + File.separator + "horizontal.xlsx"); fileHorizontal03 = TestFileUtil.createNewFile("fillHorizontal03.xls"); horizontalFillTemplate03 = TestFileUtil.readFile("fill" + File.separator + "horizontal.xls"); + byName07 = TestFileUtil.createNewFile("byName07.xlsx"); + byNameTemplate07 = TestFileUtil.readFile("fill" + File.separator + "byName.xlsx"); + byName03 = TestFileUtil.createNewFile("byName03.xls"); + byNameTemplate03 = TestFileUtil.readFile("fill" + File.separator + "byName.xls"); } @Test @@ -86,6 +94,23 @@ public class FillDataTest { horizontalFill(fileHorizontal03, horizontalFillTemplate03); } + @Test + public void t07ByNameFill07() { + byNameFill(byName07, byNameTemplate07); + } + + @Test + public void t08ByNameFill03() { + byNameFill(byName03, byNameTemplate03); + } + + private void byNameFill(File file, File template) { + FillData fillData = new FillData(); + fillData.setName("张三"); + fillData.setNumber(5.2); + EasyExcel.write(file, FillData.class).withTemplate(template).sheet("Sheet2").doFill(fillData); + } + private void horizontalFill(File file, File template) { ExcelWriter excelWriter = EasyExcel.write(file).withTemplate(template).build(); WriteSheet writeSheet = EasyExcel.writerSheet().build(); diff --git a/src/test/resources/fill/byName.xls b/src/test/res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fFI~@1&xKGDDJHG9OKM0NcdP9i#%pdp0^!wYmzegW{8ASZaJp73`{7E$Y z<`91+5jVe}#x=RcM$7BH#^q{D50Pf~fc7li@?}#sm|h&Y?M>9SQh&6#InW)SXJm z9q|6pq=CRanT&>ysZoy6G`YcN_zzGL{wPO7D;`0|4g_`hbR9qD9s}PDVB14L3$c_; zNJ)jS29kiHJlF$&>_gap8p_`W;jr^SP$%7h!zfAyA$12DCy(#H(0*rRT*v=E0CJW* ARsaA1 literal 0 HcmV?d00001 diff --git a/src/test/resources/fill/byName.xlsx b/src/test/resources/fill/byName.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..327e0557ac60ccee12309a7c44c2659436dad2ed GIT binary patch literal 11489 zcmeHt1y>yF(lzexL4reYOK>N+1Si2=2X_nZ?m>ckAh^4`OR(S?+y{RrIrsf?4mbDv z1Mls%de-#nsXg7#s$I38s*;z6gu()Y0fPer10w~Kx}==&2L}U-fdK=<1cQUn5V5v$ zFtT#cQFgU4ve#mCu>_E0LqWXC1cLzm{=din;T0HG8L;YPMr%>~A@H_UwOcT+xEPMG zkx+wT7xt422~LQmD-43yO2`Lg75Y#?bEXgs_hnYhwhNdq#WIO#atk={b4z9h zCdoj;wwjlszPTl;c~#LNZ!+;NtgYQPYG7sR7xbwR$et)Dx1p60ly*AK2B!n0&;_vN6MwFS!&fRqEDdUi$>J8m=tt!hO^gnBT-9Uyzo22?g zX4bGby_u=iT8PIjN-Stb4^~L4M2y51h>ljlf^|k>;*F6SW2Kd+`6571k9WD^k{s!B z&{l1+5%r}wGk$Cq!o^qGD@L`vdpkXTTdVYR7_)_xx$J7i-Xn*M)u>d3UX7hWVRJ9^ z`mD$!feG6uaqi$T!hV+)4+`|{VX){~%GDZyE;zTy26^y{VBqVquZ*kIS2RR~EM2R- zcA?Ow%K=)3(=!ZXf@uBi{I5}nTKUMuS9>gjxDDRy<}ckq45;8vS?i)i4*^B?ydc5A zo}M7Vr2Rk4)W5xYNvy0iBnw*LvF{V< za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oYCKHT3v zz#O*dPafbCII%49t6cF*STm*$R=dkcBCXUT{vbv{t_it}Q1>E=JqjC^P(5aM9@N(!_P}U0_h%2#D|USTjFSk3dUeVC1z^@N|u1#zhw zc}qNe_WB06wC_s}k{&ECmhA2PdNB0ucOl$d*?y=3G-+n*%@46dolaw98Ku zj|v|#sg_086Pgi$;_wr*$m{E6=J3y-{MH%ak%>CZ46v`)Oiku&Y{yKzm4qWJAjT-K z3Cnyc_Cid<;J+pgiqDJ`KcU@A!=2AQ%=xHVV+WT&S2=FI#@(h zyX>j8jAP$_?JLkz7Z>)$YPx=MUkhHa$4%gk^G6I-u2R8t#;}>YsUMez8#k1FZC#q7 za#8SzOMc;CVw|P0cDr}JaO_I=lP_;ZzNVwHTc=w!E@v1-Q3^Ch)93z?LG&1US0nU z(2Vi_{{8<~Ykv;-yjcAkuocv9{@3gL3-EX8`Z>z;s^4#vCY(Q_{Hg&yM|oZx`i-&x zs-yqmS$>s@o})b9d;do10QJy8D8F~&&rP52LVlZ`z5L7c`JUuC!ap_mZ+kE>b`mhK z=ZgHf^>e-R+a3kMvtZJO}t^>i9c=64l=U a{*_4NrJ+HD`Z Date: Thu, 2 Jan 2020 21:49:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A1=AB=E5=85=85=E6=97=B6=E5=80=99?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE`sheetName`=E5=AE=9A?= =?UTF-8?q?=E4=BD=8D`sheet`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/excel/context/WriteContextImpl.java | 6 ++---- .../excel/write/metadata/holder/WriteSheetHolder.java | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index 890bef2..df4840d 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -103,10 +103,8 @@ public class WriteContextImpl implements WriteContext { */ @Override public void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType) { - boolean illegalArgument = - writeSheet == null || (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())); - if (illegalArgument) { - throw new IllegalArgumentException("Sheet name and Sheet number can not be empty."); + if (writeSheet == null) { + throw new IllegalArgumentException("Sheet argument cannot be null"); } if (selectSheetFromCache(writeSheet)) { return; diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java index b74db29..56fc7e4 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java @@ -10,6 +10,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.enums.WriteLastRowTypeEnum; +import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.write.metadata.WriteSheet; /** @@ -67,7 +68,11 @@ public class WriteSheetHolder extends AbstractWriteHolder { public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) { super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); this.writeSheet = writeSheet; - this.sheetNo = writeSheet.getSheetNo(); + if (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())) { + this.sheetNo = 0; + } else { + this.sheetNo = writeSheet.getSheetNo(); + } this.sheetName = writeSheet.getSheetName(); this.parentWriteWorkbookHolder = writeWorkbookHolder; this.hasBeenInitializedTable = new HashMap(); From c6f21608abaf933b880e180a4ed6ee6c1d3f7109 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 3 Jan 2020 20:08:18 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A1=AB=E5=85=85?= =?UTF-8?q?=E5=8F=AA=E6=9C=89`sheetName`=E4=BC=9A=E6=8A=9B=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + pom.xml | 2 +- .../excel/context/WriteContextImpl.java | 25 +++++++++++++------ update.md | 3 +++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1251ebd..b142b9d 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ easyexcel [QQ群: 662022184](//shang.qq.com/wpa/qunwpa?idkey=53d9d821b0833e3c14670f007488a61e300f00ff4f1b81fd950590d90dd80f80) [钉钉群: 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11) [官方网站: https://alibaba-easyexcel.github.io/](https://alibaba-easyexcel.github.io/) +#### 因为公司不方便用QQ,所以建议加钉钉群 # JAVA解析Excel工具easyexcel Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,能够原本一个3M的excel用POI sax依然需要100M左右内存降低到几M,并且再大的excel不会出现内存溢出,03版依赖POI的sax模式。在上层做了模型转换的封装,让使用者更加简单方便 diff --git a/pom.xml b/pom.xml index 844f70c..fe46977 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 2.1.5 + 2.1.6 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index df4840d..e79453c 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -161,14 +161,10 @@ public class WriteContextImpl implements WriteContext { .setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheet(writeSheetHolder.getSheetName())); } } catch (Exception e) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Can not find sheet:{} ,now create it", writeSheetHolder.getSheetNo()); - } - if (StringUtils.isEmpty(writeSheetHolder.getSheetName())) { - writeSheetHolder.setSheetName(writeSheetHolder.getSheetNo().toString()); - } - currentSheet = WorkBookUtil.createSheet(writeWorkbookHolder.getWorkbook(), writeSheetHolder.getSheetName()); - writeSheetHolder.setCachedSheet(currentSheet); + currentSheet = createSheet(); + } + if (currentSheet == null) { + currentSheet = createSheet(); } writeSheetHolder.setSheet(currentSheet); WriteHandlerUtils.afterSheetCreate(this); @@ -180,6 +176,19 @@ public class WriteContextImpl implements WriteContext { writeWorkbookHolder.getHasBeenInitializedSheetNameMap().put(writeSheetHolder.getSheetName(), writeSheetHolder); } + private Sheet createSheet() { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Can not find sheet:{} ,now create it", writeSheetHolder.getSheetNo()); + } + if (StringUtils.isEmpty(writeSheetHolder.getSheetName())) { + writeSheetHolder.setSheetName(writeSheetHolder.getSheetNo().toString()); + } + Sheet currentSheet = + WorkBookUtil.createSheet(writeWorkbookHolder.getWorkbook(), writeSheetHolder.getSheetName()); + writeSheetHolder.setCachedSheet(currentSheet); + return currentSheet; + } + public void initHead(ExcelWriteHeadProperty excelWriteHeadProperty) { if (!currentWriteHolder.needHead() || !currentWriteHolder.excelWriteHeadProperty().hasHead()) { return; diff --git a/update.md b/update.md index 35ecf49..4625810 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,6 @@ +# 2.1.6 +* 修复填充只有`sheetName`会抛异常 + # 2.1.5 * 修复部分xlsx没有行号读取异常 * 填充时候支持根据`sheetName`定位`sheet` From 482c99076a1095c117b470367ff9542e64745111 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 3 Jan 2020 20:08:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A1=AB=E5=85=85?= =?UTF-8?q?=E5=8F=AA=E6=9C=89`sheetName`=E4=BC=9A=E6=8A=9B=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.md b/update.md index 4625810..864a780 100644 --- a/update.md +++ b/update.md @@ -1,5 +1,5 @@ # 2.1.6 -* 修复填充只有`sheetName`会抛异常 +* 修复写入只有`sheetName`会抛异常 # 2.1.5 * 修复部分xlsx没有行号读取异常