Browse Source

优化读写性能

pull/2159/head
Jiaju Zhuang 3 years ago
parent
commit
031fefde92
  1. 18
      src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java
  2. 7
      src/main/java/com/alibaba/excel/context/WriteContextImpl.java
  3. 4
      src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java
  4. 50
      src/main/java/com/alibaba/excel/read/metadata/holder/xlsx/XlsxReadWorkbookHolder.java
  5. 61
      src/main/java/com/alibaba/excel/util/PositionUtils.java
  6. 203
      src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java
  7. 6
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  8. 10
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  9. 63
      src/main/java/com/alibaba/excel/write/handler/chain/CellHandlerExecutionChain.java
  10. 56
      src/main/java/com/alibaba/excel/write/handler/chain/RowHandlerExecutionChain.java
  11. 48
      src/main/java/com/alibaba/excel/write/handler/chain/SheetHandlerExecutionChain.java
  12. 57
      src/main/java/com/alibaba/excel/write/handler/chain/WorkbookHandlerExecutionChain.java
  13. 9
      src/main/java/com/alibaba/excel/write/handler/context/CellWriteHandlerContext.java
  14. 8
      src/main/java/com/alibaba/excel/write/handler/context/RowWriteHandlerContext.java
  15. 12
      src/main/java/com/alibaba/excel/write/handler/context/SheetWriteHandlerContext.java
  16. 13
      src/main/java/com/alibaba/excel/write/handler/context/WorkbookWriteHandlerContext.java
  17. 183
      src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
  18. 18
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java
  19. 11
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  20. 17
      src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

18
src/main/java/com/alibaba/excel/analysis/v07/handlers/CellTagHandler.java

@ -2,19 +2,15 @@ package com.alibaba.excel.analysis.v07.handlers;
import java.math.BigDecimal;
import com.alibaba.excel.constant.BuiltinFormats;
import com.alibaba.excel.constant.ExcelXmlConstants;
import com.alibaba.excel.context.xlsx.XlsxReadContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.DataFormatData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.util.StringUtils;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.xml.sax.Attributes;
/**
@ -51,17 +47,9 @@ public class CellTagHandler extends AbstractXlsxTagHandler {
} else {
dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
}
StylesTable stylesTable = xlsxReadContext.xlsxReadWorkbookHolder().getStylesTable();
if (stylesTable == null) {
return;
}
XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(dateFormatIndexInteger);
short dataFormat = xssfCellStyle.getDataFormat();
DataFormatData dataFormatData = new DataFormatData();
dataFormatData.setIndex(dataFormat);
dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormat,
xssfCellStyle.getDataFormatString(), xlsxReadSheetHolder.getGlobalConfiguration().getLocale()));
xlsxReadSheetHolder.getTempCellData().setDataFormatData(dataFormatData);
xlsxReadSheetHolder.getTempCellData().setDataFormatData(
xlsxReadContext.xlsxReadWorkbookHolder().dataFormatData(dateFormatIndexInteger));
}
@Override

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

@ -127,7 +127,7 @@ public class WriteContextImpl implements WriteContext {
// Workbook handler need to supplementary execution
WorkbookWriteHandlerContext workbookWriteHandlerContext = WriteHandlerUtils.createWorkbookWriteHandlerContext(
this, true);
this);
WriteHandlerUtils.beforeWorkbookCreate(workbookWriteHandlerContext, true);
WriteHandlerUtils.afterWorkbookCreate(workbookWriteHandlerContext, true);
@ -310,12 +310,11 @@ public class WriteContextImpl implements WriteContext {
// Workbook and sheet handler need to supplementary execution
WorkbookWriteHandlerContext workbookWriteHandlerContext = WriteHandlerUtils.createWorkbookWriteHandlerContext(
this, true);
this);
WriteHandlerUtils.beforeWorkbookCreate(workbookWriteHandlerContext, true);
WriteHandlerUtils.afterWorkbookCreate(workbookWriteHandlerContext, true);
SheetWriteHandlerContext sheetWriteHandlerContext = WriteHandlerUtils.createSheetWriteHandlerContext(this,
true);
SheetWriteHandlerContext sheetWriteHandlerContext = WriteHandlerUtils.createSheetWriteHandlerContext(this);
WriteHandlerUtils.beforeSheetCreate(sheetWriteHandlerContext, true);
WriteHandlerUtils.afterSheetCreate(sheetWriteHandlerContext, true);

4
src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java

@ -91,7 +91,6 @@ public class ModelBuildEventListener implements ReadListener<Map<Integer, ReadCe
"Can not instance class: " + excelReadHeadProperty.getHeadClazz().getName(), e);
}
Map<Integer, Head> headMap = excelReadHeadProperty.getHeadMap();
Map<String, Object> map = MapUtils.newHashMapWithExpectedSize(headMap.size());
BeanMap dataMap = BeanMapUtils.create(resultModel);
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) {
Integer index = entry.getKey();
@ -105,10 +104,9 @@ public class ModelBuildEventListener implements ReadListener<Map<Integer, ReadCe
ClassUtils.declaredExcelContentProperty(dataMap, readSheetHolder.excelReadHeadProperty().getHeadClazz(),
fieldName), readSheetHolder.converterMap(), context, context.readRowHolder().getRowIndex(), index);
if (value != null) {
map.put(fieldName, value);
dataMap.put(fieldName, value);
}
}
dataMap.putAll(map);
return resultModel;
}

50
src/main/java/com/alibaba/excel/read/metadata/holder/xlsx/XlsxReadWorkbookHolder.java

@ -1,19 +1,26 @@
package com.alibaba.excel.read.metadata.holder.xlsx;
import javax.xml.parsers.SAXParserFactory;
import java.util.Map;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.model.StylesTable;
import javax.xml.parsers.SAXParserFactory;
import com.alibaba.excel.constant.BuiltinFormats;
import com.alibaba.excel.metadata.data.DataFormatData;
import com.alibaba.excel.read.metadata.ReadWorkbook;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import com.alibaba.excel.support.ExcelTypeEnum;
import lombok.Data;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
/**
* Workbook holder
*
* @author Jiaju Zhuang
*/
@Data
public class XlsxReadWorkbookHolder extends ReadWorkbookHolder {
/**
* Package
@ -34,6 +41,10 @@ public class XlsxReadWorkbookHolder extends ReadWorkbookHolder {
* Current style information
*/
private StylesTable stylesTable;
/**
* cache data format
*/
private Map<Integer, DataFormatData> dataFormatDataCache;
public XlsxReadWorkbookHolder(ReadWorkbook readWorkbook) {
super(readWorkbook);
@ -41,27 +52,18 @@ public class XlsxReadWorkbookHolder extends ReadWorkbookHolder {
setExcelType(ExcelTypeEnum.XLSX);
}
public OPCPackage getOpcPackage() {
return opcPackage;
public DataFormatData dataFormatData(int dateFormatIndexInteger) {
return dataFormatDataCache.computeIfAbsent(dateFormatIndexInteger, key -> {
DataFormatData dataFormatData = new DataFormatData();
if (stylesTable == null) {
return null;
}
XSSFCellStyle xssfCellStyle = stylesTable.getStyleAt(dateFormatIndexInteger);
dataFormatData.setIndex(xssfCellStyle.getDataFormat());
dataFormatData.setFormat(BuiltinFormats.getBuiltinFormat(dataFormatData.getIndex(),
xssfCellStyle.getDataFormatString(), globalConfiguration().getLocale()));
return dataFormatData;
});
}
public void setOpcPackage(OPCPackage opcPackage) {
this.opcPackage = opcPackage;
}
public String getSaxParserFactoryName() {
return saxParserFactoryName;
}
public void setSaxParserFactoryName(String saxParserFactoryName) {
this.saxParserFactoryName = saxParserFactoryName;
}
public StylesTable getStylesTable() {
return stylesTable;
}
public void setStylesTable(StylesTable stylesTable) {
this.stylesTable = stylesTable;
}
}

61
src/main/java/com/alibaba/excel/util/PositionUtils.java

@ -1,11 +1,7 @@
package com.alibaba.excel.util;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.poi.ss.util.CellReference;
/**
* @author jipengfei
*/
@ -18,14 +14,6 @@ public class PositionUtils {
private PositionUtils() {}
public static int getRowByRowTagt(String rowTagt) {
int row = 0;
if (rowTagt != null) {
row = Integer.parseInt(rowTagt) - 1;
}
return row;
}
public static int getRowByRowTagt(String rowTagt, Integer before) {
int row;
if (rowTagt != null) {
@ -37,47 +25,40 @@ public class PositionUtils {
}
return before + 1;
}
}
public static int getRow(String currentCellIndex) {
if (currentCellIndex != null) {
int plingPos = currentCellIndex.lastIndexOf(SHEET_NAME_DELIMITER);
String cell = currentCellIndex.substring(plingPos + 1).toUpperCase(Locale.ROOT);
Matcher matcher = CELL_REF_PATTERN.matcher(cell);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid CellReference: " + currentCellIndex);
if (currentCellIndex == null) {
return -1;
}
int firstNumber = currentCellIndex.length() - 1;
for (; firstNumber >= 0; firstNumber--) {
char c = currentCellIndex.charAt(firstNumber);
if (c < '0' || c > '9') {
break;
}
String row = matcher.group(2);
return Integer.parseInt(row) - 1;
}
return -1;
return Integer.parseUnsignedInt(currentCellIndex.substring(firstNumber + 1)) - 1;
}
public static int getCol(String currentCellIndex, Integer before) {
if (currentCellIndex != null) {
int plingPos = currentCellIndex.lastIndexOf(SHEET_NAME_DELIMITER);
String cell = currentCellIndex.substring(plingPos + 1).toUpperCase(Locale.ROOT);
Matcher matcher = CELL_REF_PATTERN.matcher(cell);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid CellReference: " + currentCellIndex);
}
String col = matcher.group(1);
if (col.length() > 0 && col.charAt(0) == REDUNDANT_CHARACTERS) {
col = col.substring(1);
}
if (col.length() == 0) {
return -1;
} else {
return CellReference.convertColStringToIndex(col);
}
} else {
if (currentCellIndex == null) {
if (before == null) {
before = -1;
}
return before + 1;
}
int firstNumber = currentCellIndex.charAt(0) == REDUNDANT_CHARACTERS ? 1 : 0;
int col = 0;
for (; firstNumber < currentCellIndex.length(); firstNumber++) {
char c = currentCellIndex.charAt(firstNumber);
boolean isNotLetter = c == REDUNDANT_CHARACTERS || (c >= '0' && c <= '9');
if (isNotLetter) {
break;
}
col = col * 26 + Character.toUpperCase(c) - 'A' + 1;
}
return col - 1;
}
}

203
src/main/java/com/alibaba/excel/util/WriteHandlerUtils.java

@ -1,22 +1,19 @@
package com.alibaba.excel.util;
import java.util.List;
import java.util.Map;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.handler.chain.CellHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.RowHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.SheetHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.WorkbookHandlerExecutionChain;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext;
import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext;
import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder;
import org.apache.commons.collections4.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
/**
@ -24,23 +21,14 @@ import org.apache.poi.ss.usermodel.Row;
*
* @author Jiaju Zhuang
*/
@Slf4j
public class WriteHandlerUtils {
private WriteHandlerUtils() {}
public static WorkbookWriteHandlerContext createWorkbookWriteHandlerContext(WriteContext writeContext) {
return createWorkbookWriteHandlerContext(writeContext, false);
}
public static WorkbookWriteHandlerContext createWorkbookWriteHandlerContext(WriteContext writeContext,
boolean runOwn) {
List<WriteHandler> handlerList = getHandlerList(writeContext, WorkbookWriteHandler.class, runOwn);
WorkbookWriteHandlerContext context = new WorkbookWriteHandlerContext(writeContext, null, null, null);
if (runOwn) {
context.setOwnHandlerList(handlerList);
} else {
context.setHandlerList(handlerList);
}
WorkbookWriteHandlerContext context = new WorkbookWriteHandlerContext(writeContext,
writeContext.writeWorkbookHolder());
writeContext.writeWorkbookHolder().setWorkbookWriteHandlerContext(context);
return context;
}
@ -50,16 +38,9 @@ public class WriteHandlerUtils {
}
public static void beforeWorkbookCreate(WorkbookWriteHandlerContext context, boolean runOwn) {
List<WriteHandler> handlerList;
if (runOwn) {
handlerList = context.getOwnHandlerList();
} else {
handlerList = context.getHandlerList();
}
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((WorkbookWriteHandler)writeHandler).beforeWorkbookCreate(context);
}
WorkbookHandlerExecutionChain workbookHandlerExecutionChain = getWorkbookHandlerExecutionChain(context, runOwn);
if (workbookHandlerExecutionChain != null) {
workbookHandlerExecutionChain.beforeWorkbookCreate(context);
}
}
@ -68,42 +49,32 @@ public class WriteHandlerUtils {
}
public static void afterWorkbookCreate(WorkbookWriteHandlerContext context, boolean runOwn) {
List<WriteHandler> handlerList;
WorkbookHandlerExecutionChain workbookHandlerExecutionChain = getWorkbookHandlerExecutionChain(context, runOwn);
if (workbookHandlerExecutionChain != null) {
workbookHandlerExecutionChain.afterWorkbookCreate(context);
}
}
private static WorkbookHandlerExecutionChain getWorkbookHandlerExecutionChain(WorkbookWriteHandlerContext context,
boolean runOwn) {
AbstractWriteHolder abstractWriteHolder = (AbstractWriteHolder)context.getWriteContext().currentWriteHolder();
if (runOwn) {
handlerList = context.getOwnHandlerList();
return abstractWriteHolder.getOwnWorkbookHandlerExecutionChain();
} else {
handlerList = context.getHandlerList();
}
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((WorkbookWriteHandler)writeHandler).afterWorkbookCreate(context);
}
return abstractWriteHolder.getWorkbookHandlerExecutionChain();
}
}
public static void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((WorkbookWriteHandler)writeHandler).afterWorkbookDispose(context);
}
WorkbookHandlerExecutionChain workbookHandlerExecutionChain = getWorkbookHandlerExecutionChain(context, false);
if (workbookHandlerExecutionChain != null) {
workbookHandlerExecutionChain.afterWorkbookDispose(context);
}
}
public static SheetWriteHandlerContext createSheetWriteHandlerContext(WriteContext writeContext) {
return createSheetWriteHandlerContext(writeContext, false);
}
public static SheetWriteHandlerContext createSheetWriteHandlerContext(WriteContext writeContext, boolean runOwn) {
List<WriteHandler> handlerList = getHandlerList(writeContext, SheetWriteHandler.class, runOwn);
SheetWriteHandlerContext context = new SheetWriteHandlerContext(writeContext,
writeContext.writeWorkbookHolder(), writeContext.writeSheetHolder(), null, null);
if (runOwn) {
context.setOwnHandlerList(handlerList);
} else {
context.setHandlerList(handlerList);
}
return context;
return new SheetWriteHandlerContext(writeContext, writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder());
}
public static void beforeSheetCreate(SheetWriteHandlerContext context) {
@ -111,16 +82,9 @@ public class WriteHandlerUtils {
}
public static void beforeSheetCreate(SheetWriteHandlerContext context, boolean runOwn) {
List<WriteHandler> handlerList;
if (runOwn) {
handlerList = context.getOwnHandlerList();
} else {
handlerList = context.getHandlerList();
}
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((SheetWriteHandler)writeHandler).beforeSheetCreate(context);
}
SheetHandlerExecutionChain sheetHandlerExecutionChain = getSheetHandlerExecutionChain(context, runOwn);
if (sheetHandlerExecutionChain != null) {
sheetHandlerExecutionChain.beforeSheetCreate(context);
}
}
@ -129,111 +93,90 @@ public class WriteHandlerUtils {
}
public static void afterSheetCreate(SheetWriteHandlerContext context, boolean runOwn) {
List<WriteHandler> handlerList;
SheetHandlerExecutionChain sheetHandlerExecutionChain = getSheetHandlerExecutionChain(context, runOwn);
if (sheetHandlerExecutionChain != null) {
sheetHandlerExecutionChain.afterSheetCreate(context);
}
}
private static SheetHandlerExecutionChain getSheetHandlerExecutionChain(SheetWriteHandlerContext context,
boolean runOwn) {
AbstractWriteHolder abstractWriteHolder = (AbstractWriteHolder)context.getWriteContext().currentWriteHolder();
if (runOwn) {
handlerList = context.getOwnHandlerList();
return abstractWriteHolder.getOwnSheetHandlerExecutionChain();
} else {
handlerList = context.getHandlerList();
}
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((SheetWriteHandler)writeHandler).afterSheetCreate(context);
}
return abstractWriteHolder.getSheetHandlerExecutionChain();
}
}
public static CellWriteHandlerContext createCellWriteHandlerContext(WriteContext writeContext, Row row,
Integer rowIndex, Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead,
ExcelContentProperty excelContentProperty) {
List<WriteHandler> handlerList = writeContext.currentWriteHolder().writeHandlerMap().get(
CellWriteHandler.class);
return new CellWriteHandlerContext(writeContext, writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder(), writeContext.writeTableHolder(), row, rowIndex, null, columnIndex,
relativeRowIndex, head, null, null, isHead, excelContentProperty, handlerList);
relativeRowIndex, head, null, null, isHead, excelContentProperty);
}
public static void beforeCellCreate(CellWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((CellWriteHandler)writeHandler).beforeCellCreate(context);
}
CellHandlerExecutionChain cellHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getCellHandlerExecutionChain();
if (cellHandlerExecutionChain != null) {
cellHandlerExecutionChain.beforeCellCreate(context);
}
}
public static void afterCellCreate(CellWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((CellWriteHandler)writeHandler).afterCellCreate(context);
}
CellHandlerExecutionChain cellHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getCellHandlerExecutionChain();
if (cellHandlerExecutionChain != null) {
cellHandlerExecutionChain.afterCellCreate(context);
}
}
public static void afterCellDataConverted(CellWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((CellWriteHandler)writeHandler).afterCellDataConverted(context);
}
CellHandlerExecutionChain cellHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getCellHandlerExecutionChain();
if (cellHandlerExecutionChain != null) {
cellHandlerExecutionChain.afterCellDataConverted(context);
}
}
public static void afterCellDispose(CellWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((CellWriteHandler)writeHandler).afterCellDispose(context);
}
CellHandlerExecutionChain cellHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getCellHandlerExecutionChain();
if (cellHandlerExecutionChain != null) {
cellHandlerExecutionChain.afterCellDispose(context);
}
}
public static RowWriteHandlerContext createRowWriteHandlerContext(WriteContext writeContext, Integer rowIndex,
Integer relativeRowIndex, Boolean isHead) {
List<WriteHandler> handlerList = writeContext.currentWriteHolder().writeHandlerMap().get(
RowWriteHandler.class);
return new RowWriteHandlerContext(writeContext,
writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder(), writeContext.writeTableHolder(), rowIndex, null, relativeRowIndex,
isHead, handlerList);
return new RowWriteHandlerContext(writeContext, writeContext.writeWorkbookHolder(),
writeContext.writeSheetHolder(), writeContext.writeTableHolder(), rowIndex, null, relativeRowIndex, isHead);
}
public static void beforeRowCreate(RowWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((RowWriteHandler)writeHandler).beforeRowCreate(context);
}
RowHandlerExecutionChain rowHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getRowHandlerExecutionChain();
if (rowHandlerExecutionChain != null) {
rowHandlerExecutionChain.beforeRowCreate(context);
}
}
public static void afterRowCreate(RowWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((RowWriteHandler)writeHandler).afterRowCreate(context);
}
RowHandlerExecutionChain rowHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getRowHandlerExecutionChain();
if (rowHandlerExecutionChain != null) {
rowHandlerExecutionChain.afterRowCreate(context);
}
}
public static void afterRowDispose(RowWriteHandlerContext context) {
List<WriteHandler> handlerList = context.getHandlerList();
if (CollectionUtils.isNotEmpty(handlerList)) {
for (WriteHandler writeHandler : handlerList) {
((RowWriteHandler)writeHandler).afterRowDispose(context);
}
RowHandlerExecutionChain rowHandlerExecutionChain = ((AbstractWriteHolder)context.getWriteContext()
.currentWriteHolder()).getRowHandlerExecutionChain();
if (rowHandlerExecutionChain != null) {
rowHandlerExecutionChain.afterRowDispose(context);
}
}
private static List<WriteHandler> getHandlerList(WriteContext writeContext, Class<? extends
WriteHandler> clazz,
boolean runOwn) {
Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap;
if (runOwn) {
writeHandlerMap = writeContext.currentWriteHolder().ownWriteHandlerMap();
} else {
writeHandlerMap = writeContext.currentWriteHolder().writeHandlerMap();
}
return writeHandlerMap.get(clazz);
}
}

6
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java

@ -142,6 +142,8 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
Map<Integer, Field> sortedAllFiledMap) {
WriteHolder currentWriteHolder = writeContext.currentWriteHolder();
BeanMap beanMap = BeanMapUtils.create(oneRowData);
// Bean the contains of the Map Key method with poor performance,So to create a keySet here
Set<String> beanKeySet = new HashSet<>(beanMap.keySet());
Set<String> beanMapHandledSet = new HashSet<>();
int maxCellIndex = -1;
// If it's a class it needs to be cast by type
@ -151,7 +153,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
int columnIndex = entry.getKey();
Head head = entry.getValue();
String name = head.getFieldName();
if (!beanMap.containsKey(name)) {
if (!beanKeySet.contains(name)) {
continue;
}
@ -188,7 +190,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) {
Field field = entry.getValue();
String filedName = FieldUtils.resolveCglibFieldName(field);
boolean uselessData = !beanMap.containsKey(filedName) || beanMapHandledSet.contains(filedName)
boolean uselessData = !beanKeySet.contains(filedName) || beanMapHandledSet.contains(filedName)
|| ignoreMap.containsKey(filedName);
if (uselessData) {
continue;

10
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java

@ -185,12 +185,14 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if (CollectionUtils.isEmpty(analysisCellList) || oneRowData == null) {
return;
}
Map<?, ?> dataMap;
Map dataMap;
if (oneRowData instanceof Map) {
dataMap = (Map<?, ?>)oneRowData;
dataMap = (Map)oneRowData;
} else {
dataMap = BeanMapUtils.create(oneRowData);
}
Set<String> dataKeySet = new HashSet<String>(dataMap.keySet());
for (AnalysisCell analysisCell : analysisCellList) {
CellWriteHandlerContext cellWriteHandlerContext = WriteHandlerUtils.createCellWriteHandlerContext(
writeContext, null, analysisCell.getRowIndex(), null, analysisCell.getColumnIndex(),
@ -198,7 +200,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if (analysisCell.getOnlyOneVariable()) {
String variable = analysisCell.getVariableList().get(0);
if (!dataMap.containsKey(variable)) {
if (!dataKeySet.contains(variable)) {
continue;
}
Object value = dataMap.get(variable);
@ -231,7 +233,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
for (String variable : analysisCell.getVariableList()) {
cellValueBuild.append(analysisCell.getPrepareDataList().get(index++));
if (!dataMap.containsKey(variable)) {
if (!dataKeySet.contains(variable)) {
continue;
}
Object value = dataMap.get(variable);

63
src/main/java/com/alibaba/excel/write/handler/chain/CellHandlerExecutionChain.java

@ -0,0 +1,63 @@
package com.alibaba.excel.write.handler.chain;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import lombok.Data;
/**
* Execute the cell handler chain
*
* @author Jiaju Zhuang
*/
@Data
public class CellHandlerExecutionChain {
/**
* next chain
*/
private CellHandlerExecutionChain next;
/**
* handler
*/
private CellWriteHandler handler;
public CellHandlerExecutionChain(CellWriteHandler handler) {
this.handler = handler;
}
public void beforeCellCreate(CellWriteHandlerContext context) {
this.handler.beforeCellCreate(context);
if (this.next != null) {
this.next.beforeCellCreate(context);
}
}
public void afterCellCreate(CellWriteHandlerContext context) {
this.handler.afterCellCreate(context);
if (this.next != null) {
this.next.afterCellCreate(context);
}
}
public void afterCellDataConverted(CellWriteHandlerContext context) {
this.handler.afterCellDataConverted(context);
if (this.next != null) {
this.next.afterCellDataConverted(context);
}
}
public void afterCellDispose(CellWriteHandlerContext context) {
this.handler.afterCellDispose(context);
if (this.next != null) {
this.next.afterCellDispose(context);
}
}
public void addLast(CellWriteHandler handler) {
CellHandlerExecutionChain context = this;
while (context.next != null) {
context = context.next;
}
context.next = new CellHandlerExecutionChain(handler);
}
}

56
src/main/java/com/alibaba/excel/write/handler/chain/RowHandlerExecutionChain.java

@ -0,0 +1,56 @@
package com.alibaba.excel.write.handler.chain;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
import lombok.Data;
/**
* Execute the row handler chain
*
* @author Jiaju Zhuang
*/
@Data
public class RowHandlerExecutionChain {
/**
* next chain
*/
private RowHandlerExecutionChain next;
/**
* handler
*/
private RowWriteHandler handler;
public RowHandlerExecutionChain(RowWriteHandler handler) {
this.handler = handler;
}
public void beforeRowCreate(RowWriteHandlerContext context) {
this.handler.beforeRowCreate(context);
if (this.next != null) {
this.next.beforeRowCreate(context);
}
}
public void afterRowCreate(RowWriteHandlerContext context) {
this.handler.afterRowCreate(context);
if (this.next != null) {
this.next.afterRowCreate(context);
}
}
public void afterRowDispose(RowWriteHandlerContext context) {
this.handler.afterRowDispose(context);
if (this.next != null) {
this.next.afterRowDispose(context);
}
}
public void addLast(RowWriteHandler handler) {
RowHandlerExecutionChain context = this;
while (context.next != null) {
context = context.next;
}
context.next = new RowHandlerExecutionChain(handler);
}
}

48
src/main/java/com/alibaba/excel/write/handler/chain/SheetHandlerExecutionChain.java

@ -0,0 +1,48 @@
package com.alibaba.excel.write.handler.chain;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext;
import lombok.Data;
/**
* Execute the sheet handler chain
*
* @author Jiaju Zhuang
*/
@Data
public class SheetHandlerExecutionChain {
/**
* next chain
*/
private SheetHandlerExecutionChain next;
/**
* handler
*/
private SheetWriteHandler handler;
public SheetHandlerExecutionChain(SheetWriteHandler handler) {
this.handler = handler;
}
public void beforeSheetCreate(SheetWriteHandlerContext context) {
this.handler.beforeSheetCreate(context);
if (this.next != null) {
this.next.beforeSheetCreate(context);
}
}
public void afterSheetCreate(SheetWriteHandlerContext context) {
this.handler.afterSheetCreate(context);
if (this.next != null) {
this.next.afterSheetCreate(context);
}
}
public void addLast(SheetWriteHandler handler) {
SheetHandlerExecutionChain context = this;
while (context.next != null) {
context = context.next;
}
context.next = new SheetHandlerExecutionChain(handler);
}
}

57
src/main/java/com/alibaba/excel/write/handler/chain/WorkbookHandlerExecutionChain.java

@ -0,0 +1,57 @@
package com.alibaba.excel.write.handler.chain;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.context.WorkbookWriteHandlerContext;
import lombok.Data;
/**
* Execute the workbook handler chain
*
* @author Jiaju Zhuang
*/
@Data
public class WorkbookHandlerExecutionChain {
/**
* next chain
*/
private WorkbookHandlerExecutionChain next;
/**
* handler
*/
private WorkbookWriteHandler handler;
public WorkbookHandlerExecutionChain(WorkbookWriteHandler handler) {
this.handler = handler;
}
public void beforeWorkbookCreate(WorkbookWriteHandlerContext context) {
this.handler.beforeWorkbookCreate(context);
if (this.next != null) {
this.next.beforeWorkbookCreate(context);
}
}
public void afterWorkbookCreate(WorkbookWriteHandlerContext context) {
this.handler.afterWorkbookCreate(context);
if (this.next != null) {
this.next.afterWorkbookCreate(context);
}
}
public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
this.handler.afterWorkbookDispose(context);
if (this.next != null) {
this.next.afterWorkbookDispose(context);
}
}
public void addLast(WorkbookWriteHandler handler) {
WorkbookHandlerExecutionChain context = this;
while (context.next != null) {
context = context.next;
}
context.next = new WorkbookHandlerExecutionChain(handler);
}
}

9
src/main/java/com/alibaba/excel/write/handler/context/CellWriteHandlerContext.java

@ -7,7 +7,6 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.handler.impl.FillStyleCellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
@ -106,16 +105,11 @@ public class CellWriteHandlerContext {
*/
private Boolean ignoreFillStyle;
/**
* handler
*/
private List<WriteHandler> handlerList;
public CellWriteHandlerContext(WriteContext writeContext,
WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder,
WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Cell cell, Integer columnIndex,
Integer relativeRowIndex, Head headData, List<WriteCellData<?>> cellDataList, WriteCellData<?> firstCellData,
Boolean head, ExcelContentProperty excelContentProperty, List<WriteHandler> handlerList) {
Boolean head, ExcelContentProperty excelContentProperty) {
this.writeContext = writeContext;
this.writeWorkbookHolder = writeWorkbookHolder;
this.writeSheetHolder = writeSheetHolder;
@ -130,6 +124,5 @@ public class CellWriteHandlerContext {
this.firstCellData = firstCellData;
this.head = head;
this.excelContentProperty = excelContentProperty;
this.handlerList = handlerList;
}
}

8
src/main/java/com/alibaba/excel/write/handler/context/RowWriteHandlerContext.java

@ -1,9 +1,6 @@
package com.alibaba.excel.write.handler.context;
import java.util.List;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
@ -52,9 +49,4 @@ public class RowWriteHandlerContext {
* Nullable.It is null in the case of fill data.
*/
private Boolean head;
/**
* handler
*/
private List<WriteHandler> handlerList;
}

12
src/main/java/com/alibaba/excel/write/handler/context/SheetWriteHandlerContext.java

@ -1,9 +1,6 @@
package com.alibaba.excel.write.handler.context;
import java.util.List;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
@ -30,13 +27,4 @@ public class SheetWriteHandlerContext {
* sheet
*/
private WriteSheetHolder writeSheetHolder;
/**
* handler
*/
private List<WriteHandler> handlerList;
/**
* handler
*/
private List<WriteHandler> ownHandlerList;
}

13
src/main/java/com/alibaba/excel/write/handler/context/WorkbookWriteHandlerContext.java

@ -1,9 +1,6 @@
package com.alibaba.excel.write.handler.context;
import java.util.List;
import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import lombok.AllArgsConstructor;
@ -25,14 +22,4 @@ public class WorkbookWriteHandlerContext {
* workbook
*/
private WriteWorkbookHolder writeWorkbookHolder;
/**
* handler
*/
private List<WriteHandler> handlerList;
/**
* handler
*/
private List<WriteHandler> ownHandlerList;
}

183
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java

@ -15,7 +15,6 @@ import com.alibaba.excel.converters.ConverterKeyBuild;
import com.alibaba.excel.converters.DefaultConverterLoader;
import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.event.NotRepeatExecutor;
import com.alibaba.excel.event.Order;
import com.alibaba.excel.metadata.AbstractHolder;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
@ -28,6 +27,10 @@ import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.handler.chain.CellHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.RowHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.SheetHandlerExecutionChain;
import com.alibaba.excel.write.handler.chain.WorkbookHandlerExecutionChain;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.merge.LoopMergeStrategy;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
@ -62,15 +65,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
* Excel head property
*/
private ExcelWriteHeadProperty excelWriteHeadProperty;
/**
* Write handler
*/
private Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap;
/**
* Own write handler.Created in the sheet in the workbook interceptors will not be executed because the workbook to
* create an event long past. So when initializing sheet, supplementary workbook event.
*/
private Map<Class<? extends WriteHandler>, List<WriteHandler>> ownWriteHandlerMap;
/**
* Use the default style.Default is true.
*/
@ -97,6 +91,43 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
*/
private Collection<String> includeColumnFieldNames;
/**
* Write handler
*/
private List<WriteHandler> writeHandlerList;
/**
* Execute the workbook handler chain
* Created in the sheet in the workbook interceptors will not be executed because the workbook to
* create an event long past. So when initializing sheet, supplementary workbook event.
*/
public WorkbookHandlerExecutionChain ownWorkbookHandlerExecutionChain;
/**
* Execute the sheet handler chain
* Created in the sheet in the workbook interceptors will not be executed because the workbook to
* create an event long past. So when initializing sheet, supplementary workbook event.
*/
public SheetHandlerExecutionChain ownSheetHandlerExecutionChain;
/**
* Execute the workbook handler chain
*/
public WorkbookHandlerExecutionChain workbookHandlerExecutionChain;
/**
* Execute the sheet handler chain
*/
public SheetHandlerExecutionChain sheetHandlerExecutionChain;
/**
* Execute the row handler chain
*/
public RowHandlerExecutionChain rowHandlerExecutionChain;
/**
* Execute the cell handler chain
*/
public CellHandlerExecutionChain cellHandlerExecutionChain;
public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder) {
super(writeBasicParameter, parentAbstractWriteHolder);
@ -169,7 +200,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
this.excelWriteHeadProperty = new ExcelWriteHeadProperty(this, getClazz(), getHead());
// Set writeHandlerMap
List<WriteHandler> handlerList = new ArrayList<WriteHandler>();
List<WriteHandler> handlerList = new ArrayList<>();
// Initialization Annotation
initAnnotationConfig(handlerList, writeBasicParameter);
@ -178,16 +209,16 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
&& !writeBasicParameter.getCustomWriteHandlerList().isEmpty()) {
handlerList.addAll(writeBasicParameter.getCustomWriteHandlerList());
}
sortAndClearUpHandler(handlerList, true);
this.ownWriteHandlerMap = sortAndClearUpHandler(handlerList);
Map<Class<? extends WriteHandler>, List<WriteHandler>> parentWriteHandlerMap = null;
if (parentAbstractWriteHolder != null) {
parentWriteHandlerMap = parentAbstractWriteHolder.getWriteHandlerMap();
if (CollectionUtils.isNotEmpty(parentAbstractWriteHolder.getWriteHandlerList())) {
handlerList.addAll(parentAbstractWriteHolder.getWriteHandlerList());
}
} else {
handlerList.addAll(DefaultWriteHandlerLoader.loadDefaultHandler(useDefaultStyle));
}
this.writeHandlerMap = sortAndClearUpAllHandler(handlerList, parentWriteHandlerMap);
sortAndClearUpHandler(handlerList, false);
// Set converterMap
if (parentAbstractWriteHolder == null) {
@ -229,7 +260,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
}
//if (hasStyle) {
dealStyle(handlerList);
dealStyle(handlerList);
//}
dealRowHigh(handlerList);
@ -310,38 +341,22 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
handlerList.add(columnWidthStyleStrategy);
}
protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpAllHandler(
List<WriteHandler> handlerList, Map<Class<? extends WriteHandler>, List<WriteHandler>> parentHandlerMap) {
// add
if (parentHandlerMap != null) {
List<WriteHandler> parentWriteHandler = parentHandlerMap.get(WriteHandler.class);
if (!CollectionUtils.isEmpty(parentWriteHandler)) {
handlerList.addAll(parentWriteHandler);
}
}
return sortAndClearUpHandler(handlerList);
}
protected Map<Class<? extends WriteHandler>, List<WriteHandler>> sortAndClearUpHandler(
List<WriteHandler> handlerList) {
protected void sortAndClearUpHandler(List<WriteHandler> handlerList, boolean runOwn) {
// sort
Map<Integer, List<WriteHandler>> orderExcelWriteHandlerMap = new TreeMap<Integer, List<WriteHandler>>();
Map<Integer, List<WriteHandler>> orderExcelWriteHandlerMap = new TreeMap<>();
for (WriteHandler handler : handlerList) {
int order = Integer.MIN_VALUE;
if (handler instanceof Order) {
order = ((Order)handler).order();
}
int order = handler.order();
if (orderExcelWriteHandlerMap.containsKey(order)) {
orderExcelWriteHandlerMap.get(order).add(handler);
} else {
List<WriteHandler> tempHandlerList = new ArrayList<WriteHandler>();
List<WriteHandler> tempHandlerList = new ArrayList<>();
tempHandlerList.add(handler);
orderExcelWriteHandlerMap.put(order, tempHandlerList);
}
}
// clean up
Set<String> alreadyExistedHandlerSet = new HashSet<String>();
List<WriteHandler> cleanUpHandlerList = new ArrayList<WriteHandler>();
Set<String> alreadyExistedHandlerSet = new HashSet<>();
List<WriteHandler> cleanUpHandlerList = new ArrayList<>();
for (Map.Entry<Integer, List<WriteHandler>> entry : orderExcelWriteHandlerMap.entrySet()) {
for (WriteHandler handler : entry.getValue()) {
if (handler instanceof NotRepeatExecutor) {
@ -354,30 +369,74 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
cleanUpHandlerList.add(handler);
}
}
// classify
Map<Class<? extends WriteHandler>, List<WriteHandler>> result =
new HashMap<Class<? extends WriteHandler>, List<WriteHandler>>(16);
result.put(WriteHandler.class, new ArrayList<WriteHandler>());
result.put(WorkbookWriteHandler.class, new ArrayList<WriteHandler>());
result.put(SheetWriteHandler.class, new ArrayList<WriteHandler>());
result.put(RowWriteHandler.class, new ArrayList<WriteHandler>());
result.put(CellWriteHandler.class, new ArrayList<WriteHandler>());
// build chain
if (!runOwn) {
this.writeHandlerList = new ArrayList<>();
}
for (WriteHandler writeHandler : cleanUpHandlerList) {
if (writeHandler instanceof CellWriteHandler) {
result.get(CellWriteHandler.class).add(writeHandler);
buildChain(writeHandler, runOwn);
}
}
protected void buildChain(WriteHandler writeHandler, boolean runOwn) {
if (writeHandler instanceof CellWriteHandler) {
if (!runOwn) {
if (cellHandlerExecutionChain == null) {
cellHandlerExecutionChain = new CellHandlerExecutionChain((CellWriteHandler)writeHandler);
} else {
cellHandlerExecutionChain.addLast((CellWriteHandler)writeHandler);
}
this.writeHandlerList.add(writeHandler);
}
if (writeHandler instanceof RowWriteHandler) {
result.get(RowWriteHandler.class).add(writeHandler);
return;
}
if (writeHandler instanceof RowWriteHandler) {
if (!runOwn) {
if (rowHandlerExecutionChain == null) {
rowHandlerExecutionChain = new RowHandlerExecutionChain((RowWriteHandler)writeHandler);
} else {
rowHandlerExecutionChain.addLast((RowWriteHandler)writeHandler);
}
this.writeHandlerList.add(writeHandler);
}
if (writeHandler instanceof SheetWriteHandler) {
result.get(SheetWriteHandler.class).add(writeHandler);
return;
}
if (writeHandler instanceof SheetWriteHandler) {
if (!runOwn) {
if (sheetHandlerExecutionChain == null) {
sheetHandlerExecutionChain = new SheetHandlerExecutionChain((SheetWriteHandler)writeHandler);
} else {
sheetHandlerExecutionChain.addLast((SheetWriteHandler)writeHandler);
}
this.writeHandlerList.add(writeHandler);
} else {
if (ownSheetHandlerExecutionChain == null) {
ownSheetHandlerExecutionChain = new SheetHandlerExecutionChain((SheetWriteHandler)writeHandler);
} else {
ownSheetHandlerExecutionChain.addLast((SheetWriteHandler)writeHandler);
}
}
if (writeHandler instanceof WorkbookWriteHandler) {
result.get(WorkbookWriteHandler.class).add(writeHandler);
return;
}
if (writeHandler instanceof WorkbookWriteHandler) {
if (!runOwn) {
if (workbookHandlerExecutionChain == null) {
workbookHandlerExecutionChain = new WorkbookHandlerExecutionChain(
(WorkbookWriteHandler)writeHandler);
} else {
workbookHandlerExecutionChain.addLast((WorkbookWriteHandler)writeHandler);
}
this.writeHandlerList.add(writeHandler);
} else {
if (ownWorkbookHandlerExecutionChain == null) {
ownWorkbookHandlerExecutionChain = new WorkbookHandlerExecutionChain(
(WorkbookWriteHandler)writeHandler);
} else {
ownWorkbookHandlerExecutionChain.addLast((WorkbookWriteHandler)writeHandler);
}
}
result.get(WriteHandler.class).add(writeHandler);
}
return result;
}
@Override
@ -406,16 +465,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
return getExcelWriteHeadProperty();
}
@Override
public Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap() {
return getWriteHandlerMap();
}
@Override
public Map<Class<? extends WriteHandler>, List<WriteHandler>> ownWriteHandlerMap() {
return getOwnWriteHandlerMap();
}
@Override
public boolean needHead() {
return getNeedHead();

18
src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java

@ -1,10 +1,6 @@
package com.alibaba.excel.write.metadata.holder;
import java.util.List;
import java.util.Map;
import com.alibaba.excel.metadata.ConfigurationHolder;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.excel.write.property.ExcelWriteHeadProperty;
/**
@ -21,20 +17,6 @@ public interface WriteHolder extends ConfigurationHolder {
*/
ExcelWriteHeadProperty excelWriteHeadProperty();
/**
* What handler does the currently operated cell need to execute
*
* @return
*/
Map<Class<? extends WriteHandler>, List<WriteHandler>> writeHandlerMap();
/**
* create your own write handler.
*
* @return
*/
Map<Class<? extends WriteHandler>, List<WriteHandler>> ownWriteHandlerMap();
/**
* Is to determine if a field needs to be ignored
*

11
src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java

@ -259,8 +259,6 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
if (writeCellStyle == null) {
return originCellStyle;
}
WriteCellStyle tempWriteCellStyle = new WriteCellStyle();
WriteCellStyle.merge(writeCellStyle, tempWriteCellStyle);
short styleIndex = -1;
Font originFont = null;
@ -277,14 +275,17 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
Map<WriteCellStyle, CellStyle> cellStyleMap = cellStyleIndexMap.computeIfAbsent(styleIndex,
key -> MapUtils.newHashMap());
CellStyle cellStyle = cellStyleMap.get(tempWriteCellStyle);
CellStyle cellStyle = cellStyleMap.get(writeCellStyle);
if (cellStyle != null) {
return cellStyle;
}
if (log.isDebugEnabled()) {
log.info("create new style:{},{}", tempWriteCellStyle, originCellStyle);
log.info("create new style:{},{}", writeCellStyle, originCellStyle);
}
cellStyle = StyleUtil.buildCellStyle(workbook, originCellStyle, writeCellStyle);
WriteCellStyle tempWriteCellStyle = new WriteCellStyle();
WriteCellStyle.merge(writeCellStyle, tempWriteCellStyle);
cellStyle = StyleUtil.buildCellStyle(workbook, originCellStyle, tempWriteCellStyle);
Short dataFormat = createDataFormat(tempWriteCellStyle.getDataFormatData(), useCache);
if (dataFormat != null) {
cellStyle.setDataFormat(dataFormat);

17
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

@ -8,6 +8,7 @@ import java.util.List;
import com.alibaba.easyexcel.test.demo.write.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.PositionUtils;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
@ -147,4 +148,20 @@ public class Lock2Test {
Thread.sleep(500 * 1000);
}
@Test
public void test335() throws Exception {
LOGGER.info("reslut:{}", PositionUtils.getCol("A10",null));
LOGGER.info("reslut:{}", PositionUtils.getRow("A10"));
LOGGER.info("reslut:{}", PositionUtils.getCol("AB10",null));
LOGGER.info("reslut:{}", PositionUtils.getRow("AB10"));
//LOGGER.info("reslut:{}", PositionUtils2.getCol("A10",null));
//LOGGER.info("reslut:{}", PositionUtils2.getRow("A10"));
//LOGGER.info("reslut:{}", PositionUtils2.getCol("AB10",null));
//LOGGER.info("reslut:{}", PositionUtils2.getRow("AB10"));
}
}

Loading…
Cancel
Save