Browse Source

修复样式可能超过最大限制的bug

bugfix
Jiaju Zhuang 3 years ago
parent
commit
68200389fb
  1. 21
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  2. 1
      update.md

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

@ -10,6 +10,7 @@ import java.io.OutputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.enums.HolderEnum;
import com.alibaba.excel.exception.ExcelGenerateException; import com.alibaba.excel.exception.ExcelGenerateException;
@ -133,15 +134,15 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
/** /**
* Used to cell style. * Used to cell style.
*/ */
private Map<Short, Map<WriteCellStyle, CellStyle>> cellStyleIndexMap; private Map<Short, Map<String, CellStyle>> cellStyleIndexMap;
/** /**
* Used to font. * Used to font.
*/ */
private Map<WriteFont, Font> fontMap; private Map<String, Font> fontMap;
/** /**
* Used to data format. * Used to data format.
*/ */
private Map<DataFormatData, Short> dataFormatMap; private Map<String, Short> dataFormatMap;
public WriteWorkbookHolder(WriteWorkbook writeWorkbook) { public WriteWorkbookHolder(WriteWorkbook writeWorkbook) {
super(writeWorkbook, null); super(writeWorkbook, null);
@ -267,9 +268,9 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
useCache = false; useCache = false;
} }
Map<WriteCellStyle, CellStyle> cellStyleMap = cellStyleIndexMap.computeIfAbsent(styleIndex, Map<String, CellStyle> cellStyleMap = cellStyleIndexMap.computeIfAbsent(styleIndex,
key -> MapUtils.newHashMap()); key -> MapUtils.newHashMap());
CellStyle cellStyle = cellStyleMap.get(writeCellStyle); CellStyle cellStyle = cellStyleMap.get(Objects.toString(writeCellStyle));
if (cellStyle != null) { if (cellStyle != null) {
return cellStyle; return cellStyle;
} }
@ -285,7 +286,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
if (font != null) { if (font != null) {
cellStyle.setFont(font); cellStyle.setFont(font);
} }
cellStyleMap.put(writeCellStyle, cellStyle); cellStyleMap.put(Objects.toString(writeCellStyle), cellStyle);
return cellStyle; return cellStyle;
} }
@ -301,12 +302,12 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
if (!useCache) { if (!useCache) {
return StyleUtil.buildFont(workbook, originFont, writeFont); return StyleUtil.buildFont(workbook, originFont, writeFont);
} }
Font font = fontMap.get(writeFont); Font font = fontMap.get(Objects.toString(writeFont));
if (font != null) { if (font != null) {
return font; return font;
} }
font = StyleUtil.buildFont(workbook, originFont, writeFont); font = StyleUtil.buildFont(workbook, originFont, writeFont);
fontMap.put(writeFont, font); fontMap.put(Objects.toString(writeFont), font);
return font; return font;
} }
@ -324,12 +325,12 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
if (!useCache) { if (!useCache) {
return StyleUtil.buildDataFormat(workbook, dataFormatData); return StyleUtil.buildDataFormat(workbook, dataFormatData);
} }
Short dataFormat = dataFormatMap.get(dataFormatData); Short dataFormat = dataFormatMap.get(Objects.toString(dataFormatData));
if (dataFormat != null) { if (dataFormat != null) {
return dataFormat; return dataFormat;
} }
dataFormat = StyleUtil.buildDataFormat(workbook, dataFormatData); dataFormat = StyleUtil.buildDataFormat(workbook, dataFormatData);
dataFormatMap.put(dataFormatData, dataFormat); dataFormatMap.put(Objects.toString(dataFormatData), dataFormat);
return dataFormat; return dataFormat;
} }

1
update.md

@ -3,6 +3,7 @@
* 修复填充样式可能丢失的问题 [Issue #2124](https://github.com/alibaba/easyexcel/issues/2124) * 修复填充样式可能丢失的问题 [Issue #2124](https://github.com/alibaba/easyexcel/issues/2124)
* 修复填充数据为空 可能NPE的bug * 修复填充数据为空 可能NPE的bug
* 修复填充样式可能不生效bug * 修复填充样式可能不生效bug
* 修复样式可能超过最大限制的bug
# 3.0.0-beta3 # 3.0.0-beta3

Loading…
Cancel
Save