Browse Source

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

pull/1050/head
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
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;

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.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<Integer, WriteTableHolder>();

Loading…
Cancel
Save