Browse Source

填充时候支持根据`sheetName`定位`sheet`

bugfix
Jiaju Zhuang 5 years ago
parent
commit
15cefb5844
  1. 6
      src/main/java/com/alibaba/excel/context/WriteContextImpl.java
  2. 7
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java

6
src/main/java/com/alibaba/excel/context/WriteContextImpl.java

@ -103,10 +103,8 @@ public class WriteContextImpl implements WriteContext {
*/ */
@Override @Override
public void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType) { public void currentSheet(WriteSheet writeSheet, WriteTypeEnum writeType) {
boolean illegalArgument = if (writeSheet == null) {
writeSheet == null || (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())); throw new IllegalArgumentException("Sheet argument cannot be null");
if (illegalArgument) {
throw new IllegalArgumentException("Sheet name and Sheet number can not be empty.");
} }
if (selectSheetFromCache(writeSheet)) { if (selectSheetFromCache(writeSheet)) {
return; return;

7
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.HolderEnum;
import com.alibaba.excel.enums.WriteLastRowTypeEnum; import com.alibaba.excel.enums.WriteLastRowTypeEnum;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
/** /**
@ -67,7 +68,11 @@ public class WriteSheetHolder extends AbstractWriteHolder {
public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) { public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) {
super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled());
this.writeSheet = writeSheet; 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.sheetName = writeSheet.getSheetName();
this.parentWriteWorkbookHolder = writeWorkbookHolder; this.parentWriteWorkbookHolder = writeWorkbookHolder;
this.hasBeenInitializedTable = new HashMap<Integer, WriteTableHolder>(); this.hasBeenInitializedTable = new HashMap<Integer, WriteTableHolder>();

Loading…
Cancel
Save