From 89c750aa57821197e7892234091e7350092c3374 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 29 Oct 2021 19:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9style=20=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/alibaba/excel/util/StyleUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/excel/util/StyleUtil.java b/src/main/java/com/alibaba/excel/util/StyleUtil.java index 1bafcdc8..e8a503d7 100644 --- a/src/main/java/com/alibaba/excel/util/StyleUtil.java +++ b/src/main/java/com/alibaba/excel/util/StyleUtil.java @@ -1,5 +1,7 @@ package com.alibaba.excel.util; +import java.util.Optional; + import com.alibaba.excel.constant.BuiltinFormats; import com.alibaba.excel.metadata.data.DataFormatData; import com.alibaba.excel.metadata.data.HyperlinkData; @@ -189,7 +191,11 @@ public class StyleUtil { xssfFont.setStrikeout(xssfOriginFont.getStrikeout()); // Colors cannot be overwritten if (writeFont == null || writeFont.getColor() == null) { - xssfFont.setColor(new XSSFColor(xssfOriginFont.getXSSFColor().getRGB(), null)); + xssfFont.setColor(Optional.of(xssfOriginFont) + .map(XSSFFont::getXSSFColor) + .map(XSSFColor::getRGB) + .map(rgb -> new XSSFColor(rgb, null)) + .orElse(null)); } xssfFont.setTypeOffset(xssfOriginFont.getTypeOffset()); xssfFont.setUnderline(xssfOriginFont.getUnderline());