diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java index 494473dc..73a680d6 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java +++ b/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.util.HashMap; import java.util.Map; +import java.util.Objects; import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.exception.ExcelGenerateException; @@ -133,15 +134,15 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { /** * Used to cell style. */ - private Map> cellStyleIndexMap; + private Map> cellStyleIndexMap; /** * Used to font. */ - private Map fontMap; + private Map fontMap; /** * Used to data format. */ - private Map dataFormatMap; + private Map dataFormatMap; public WriteWorkbookHolder(WriteWorkbook writeWorkbook) { super(writeWorkbook, null); @@ -267,9 +268,9 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { useCache = false; } - Map cellStyleMap = cellStyleIndexMap.computeIfAbsent(styleIndex, + Map cellStyleMap = cellStyleIndexMap.computeIfAbsent(styleIndex, key -> MapUtils.newHashMap()); - CellStyle cellStyle = cellStyleMap.get(writeCellStyle); + CellStyle cellStyle = cellStyleMap.get(Objects.toString(writeCellStyle)); if (cellStyle != null) { return cellStyle; } @@ -285,7 +286,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { if (font != null) { cellStyle.setFont(font); } - cellStyleMap.put(writeCellStyle, cellStyle); + cellStyleMap.put(Objects.toString(writeCellStyle), cellStyle); return cellStyle; } @@ -301,12 +302,12 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { if (!useCache) { return StyleUtil.buildFont(workbook, originFont, writeFont); } - Font font = fontMap.get(writeFont); + Font font = fontMap.get(Objects.toString(writeFont)); if (font != null) { return font; } font = StyleUtil.buildFont(workbook, originFont, writeFont); - fontMap.put(writeFont, font); + fontMap.put(Objects.toString(writeFont), font); return font; } @@ -324,12 +325,12 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { if (!useCache) { return StyleUtil.buildDataFormat(workbook, dataFormatData); } - Short dataFormat = dataFormatMap.get(dataFormatData); + Short dataFormat = dataFormatMap.get(Objects.toString(dataFormatData)); if (dataFormat != null) { return dataFormat; } dataFormat = StyleUtil.buildDataFormat(workbook, dataFormatData); - dataFormatMap.put(dataFormatData, dataFormat); + dataFormatMap.put(Objects.toString(dataFormatData), dataFormat); return dataFormat; } diff --git a/update.md b/update.md index 70e11c8c..bb9763b1 100644 --- a/update.md +++ b/update.md @@ -3,6 +3,7 @@ * 修复填充样式可能丢失的问题 [Issue #2124](https://github.com/alibaba/easyexcel/issues/2124) * 修复填充数据为空 可能NPE的bug * 修复填充样式可能不生效bug +* 修复样式可能超过最大限制的bug # 3.0.0-beta3