From 15cefb58449982a455ef92d40d3d1f7571fd3493 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 2 Jan 2020 21:49:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A1=AB=E5=85=85=E6=97=B6=E5=80=99=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=A0=B9=E6=8D=AE`sheetName`=E5=AE=9A=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 890bef21..df4840d0 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 b74db290..56fc7e4e 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();