|
|
@ -108,34 +108,39 @@ public class WriteContextImpl implements WriteContext { |
|
|
|
if (writeSheet == null) { |
|
|
|
if (writeSheet == null) { |
|
|
|
throw new IllegalArgumentException("Sheet argument cannot be null"); |
|
|
|
throw new IllegalArgumentException("Sheet argument cannot be null"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (writeSheet.getSheetNo() == null || writeSheet.getSheetNo() <= 0) { |
|
|
|
if (selectSheetFromCache(writeSheet)) { |
|
|
|
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"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
initCurrentSheetHolder(writeSheet); |
|
|
|
initCurrentSheetHolder(writeSheet); |
|
|
|
WriteHandlerUtils.beforeSheetCreate(this); |
|
|
|
|
|
|
|
// Initialization current sheet
|
|
|
|
// Initialization current sheet
|
|
|
|
initSheet(writeType); |
|
|
|
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) { |
|
|
|
private void initCurrentSheetHolder(WriteSheet writeSheet) { |
|
|
|
writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder); |
|
|
|
writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder); |
|
|
|
writeWorkbookHolder.getHasBeenInitializedSheet().put(writeSheet.getSheetNo(), writeSheetHolder); |
|
|
|
|
|
|
|
writeTableHolder = null; |
|
|
|
writeTableHolder = null; |
|
|
|
currentWriteHolder = writeSheetHolder; |
|
|
|
currentWriteHolder = writeSheetHolder; |
|
|
|
if (LOGGER.isDebugEnabled()) { |
|
|
|
if (LOGGER.isDebugEnabled()) { |
|
|
@ -144,17 +149,24 @@ public class WriteContextImpl implements WriteContext { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initSheet(WriteTypeEnum writeType) { |
|
|
|
private void initSheet(WriteTypeEnum writeType) { |
|
|
|
|
|
|
|
WriteHandlerUtils.beforeSheetCreate(this); |
|
|
|
Sheet currentSheet; |
|
|
|
Sheet currentSheet; |
|
|
|
try { |
|
|
|
try { |
|
|
|
currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo()); |
|
|
|
if (writeSheetHolder.getSheetNo() != null) { |
|
|
|
writeSheetHolder |
|
|
|
currentSheet = writeWorkbookHolder.getWorkbook().getSheetAt(writeSheetHolder.getSheetNo()); |
|
|
|
.setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo())); |
|
|
|
writeSheetHolder |
|
|
|
} catch (Exception e) { |
|
|
|
.setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheetAt(writeSheetHolder.getSheetNo())); |
|
|
|
if (LOGGER.isDebugEnabled()) { |
|
|
|
} else { |
|
|
|
LOGGER.debug("Can not find sheet:{} ,now create it", writeSheetHolder.getSheetNo()); |
|
|
|
// sheet name must not null
|
|
|
|
|
|
|
|
currentSheet = writeWorkbookHolder.getWorkbook().getSheet(writeSheetHolder.getSheetName()); |
|
|
|
|
|
|
|
writeSheetHolder |
|
|
|
|
|
|
|
.setCachedSheet(writeWorkbookHolder.getCachedWorkbook().getSheet(writeSheetHolder.getSheetName())); |
|
|
|
} |
|
|
|
} |
|
|
|
currentSheet = WorkBookUtil.createSheet(writeWorkbookHolder.getWorkbook(), writeSheetHolder.getSheetName()); |
|
|
|
} catch (Exception e) { |
|
|
|
writeSheetHolder.setCachedSheet(currentSheet); |
|
|
|
currentSheet = createSheet(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (currentSheet == null) { |
|
|
|
|
|
|
|
currentSheet = createSheet(); |
|
|
|
} |
|
|
|
} |
|
|
|
writeSheetHolder.setSheet(currentSheet); |
|
|
|
writeSheetHolder.setSheet(currentSheet); |
|
|
|
WriteHandlerUtils.afterSheetCreate(this); |
|
|
|
WriteHandlerUtils.afterSheetCreate(this); |
|
|
@ -162,6 +174,21 @@ public class WriteContextImpl implements WriteContext { |
|
|
|
// Initialization head
|
|
|
|
// Initialization head
|
|
|
|
initHead(writeSheetHolder.excelWriteHeadProperty()); |
|
|
|
initHead(writeSheetHolder.excelWriteHeadProperty()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
writeWorkbookHolder.getHasBeenInitializedSheetIndexMap().put(writeSheetHolder.getSheetNo(), writeSheetHolder); |
|
|
|
|
|
|
|
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) { |
|
|
|
public void initHead(ExcelWriteHeadProperty excelWriteHeadProperty) { |
|
|
|