From b6b37e3287cdd7ff99ec8828ad5ed88b432e25de Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Sat, 18 Sep 2021 16:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../write/metadata/style/WriteCellStyle.java | 211 +++++++++--------- 1 file changed, 111 insertions(+), 100 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java index fcbbdaed..9298f9da 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java +++ b/src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java @@ -236,110 +236,121 @@ public class WriteCellStyle { return null; } WriteCellStyle writeCellStyle = new WriteCellStyle(); - if (styleProperty != null) { - if (styleProperty.getDataFormatData() != null) { - if (writeCellStyle.getDataFormatData() == null) { - writeCellStyle.setDataFormatData(styleProperty.getDataFormatData()); - } else { - DataFormatData.merge(styleProperty.getDataFormatData(), writeCellStyle.getDataFormatData()); - } - } - if (styleProperty.getHidden() != null) { - writeCellStyle.setHidden(styleProperty.getHidden()); - } - if (styleProperty.getLocked() != null) { - writeCellStyle.setLocked(styleProperty.getLocked()); - } - if (styleProperty.getQuotePrefix() != null) { - writeCellStyle.setQuotePrefix(styleProperty.getQuotePrefix()); - } - if (styleProperty.getHorizontalAlignment() != null) { - writeCellStyle.setHorizontalAlignment(styleProperty.getHorizontalAlignment()); - } - if (styleProperty.getWrapped() != null) { - writeCellStyle.setWrapped(styleProperty.getWrapped()); - } - if (styleProperty.getVerticalAlignment() != null) { - writeCellStyle.setVerticalAlignment(styleProperty.getVerticalAlignment()); - } - if (styleProperty.getRotation() != null) { - writeCellStyle.setRotation(styleProperty.getRotation()); - } - if (styleProperty.getIndent() != null) { - writeCellStyle.setIndent(styleProperty.getIndent()); - } - if (styleProperty.getBorderLeft() != null) { - writeCellStyle.setBorderLeft(styleProperty.getBorderLeft()); - } - if (styleProperty.getBorderRight() != null) { - writeCellStyle.setBorderRight(styleProperty.getBorderRight()); - } - if (styleProperty.getBorderTop() != null) { - writeCellStyle.setBorderTop(styleProperty.getBorderTop()); - } - if (styleProperty.getBorderBottom() != null) { - writeCellStyle.setBorderBottom(styleProperty.getBorderBottom()); - } - if (styleProperty.getLeftBorderColor() != null) { - writeCellStyle.setLeftBorderColor(styleProperty.getLeftBorderColor()); - } - if (styleProperty.getRightBorderColor() != null) { - writeCellStyle.setRightBorderColor(styleProperty.getRightBorderColor()); - } - if (styleProperty.getTopBorderColor() != null) { - writeCellStyle.setTopBorderColor(styleProperty.getTopBorderColor()); - } - if (styleProperty.getBottomBorderColor() != null) { - writeCellStyle.setBottomBorderColor(styleProperty.getBottomBorderColor()); - } - if (styleProperty.getFillPatternType() != null) { - writeCellStyle.setFillPatternType(styleProperty.getFillPatternType()); - } - if (styleProperty.getFillBackgroundColor() != null) { - writeCellStyle.setFillBackgroundColor(styleProperty.getFillBackgroundColor()); - } - if (styleProperty.getFillForegroundColor() != null) { - writeCellStyle.setFillForegroundColor(styleProperty.getFillForegroundColor()); - } - if (styleProperty.getShrinkToFit() != null) { - writeCellStyle.setShrinkToFit(styleProperty.getShrinkToFit()); - } + buildStyleProperty(styleProperty, writeCellStyle); + buildFontProperty(fontProperty, writeCellStyle); + return writeCellStyle; + } + + private static void buildFontProperty(FontProperty fontProperty, WriteCellStyle writeCellStyle) { + if (fontProperty == null) { + return; } - if (fontProperty != null) { - if (writeCellStyle.getWriteFont() == null) { - writeCellStyle.setWriteFont(new WriteFont()); - } - WriteFont writeFont = writeCellStyle.getWriteFont(); + if (writeCellStyle.getWriteFont() == null) { + writeCellStyle.setWriteFont(new WriteFont()); + } + WriteFont writeFont = writeCellStyle.getWriteFont(); - if (StringUtils.isNotBlank(fontProperty.getFontName())) { - writeFont.setFontName(fontProperty.getFontName()); - } - if (fontProperty.getFontHeightInPoints() != null) { - writeFont.setFontHeightInPoints(fontProperty.getFontHeightInPoints()); - } - if (fontProperty.getItalic() != null) { - writeFont.setItalic(fontProperty.getItalic()); - } - if (fontProperty.getStrikeout() != null) { - writeFont.setStrikeout(fontProperty.getStrikeout()); - } - if (fontProperty.getColor() != null) { - writeFont.setColor(fontProperty.getColor()); - } - if (fontProperty.getTypeOffset() != null) { - writeFont.setTypeOffset(fontProperty.getTypeOffset()); - } - if (fontProperty.getUnderline() != null) { - writeFont.setUnderline(fontProperty.getUnderline()); - } - if (fontProperty.getCharset() != null) { - writeFont.setCharset(fontProperty.getCharset()); - } - if (fontProperty.getBold() != null) { - writeFont.setBold(fontProperty.getBold()); + if (StringUtils.isNotBlank(fontProperty.getFontName())) { + writeFont.setFontName(fontProperty.getFontName()); + } + if (fontProperty.getFontHeightInPoints() != null) { + writeFont.setFontHeightInPoints(fontProperty.getFontHeightInPoints()); + } + if (fontProperty.getItalic() != null) { + writeFont.setItalic(fontProperty.getItalic()); + } + if (fontProperty.getStrikeout() != null) { + writeFont.setStrikeout(fontProperty.getStrikeout()); + } + if (fontProperty.getColor() != null) { + writeFont.setColor(fontProperty.getColor()); + } + if (fontProperty.getTypeOffset() != null) { + writeFont.setTypeOffset(fontProperty.getTypeOffset()); + } + if (fontProperty.getUnderline() != null) { + writeFont.setUnderline(fontProperty.getUnderline()); + } + if (fontProperty.getCharset() != null) { + writeFont.setCharset(fontProperty.getCharset()); + } + if (fontProperty.getBold() != null) { + writeFont.setBold(fontProperty.getBold()); + } + } + + private static void buildStyleProperty(StyleProperty styleProperty, WriteCellStyle writeCellStyle) { + if (styleProperty == null) { + return; + } + if (styleProperty.getDataFormatData() != null) { + if (writeCellStyle.getDataFormatData() == null) { + writeCellStyle.setDataFormatData(styleProperty.getDataFormatData()); + } else { + DataFormatData.merge(styleProperty.getDataFormatData(), writeCellStyle.getDataFormatData()); } } - return writeCellStyle; + if (styleProperty.getHidden() != null) { + writeCellStyle.setHidden(styleProperty.getHidden()); + } + if (styleProperty.getLocked() != null) { + writeCellStyle.setLocked(styleProperty.getLocked()); + } + if (styleProperty.getQuotePrefix() != null) { + writeCellStyle.setQuotePrefix(styleProperty.getQuotePrefix()); + } + if (styleProperty.getHorizontalAlignment() != null) { + writeCellStyle.setHorizontalAlignment(styleProperty.getHorizontalAlignment()); + } + if (styleProperty.getWrapped() != null) { + writeCellStyle.setWrapped(styleProperty.getWrapped()); + } + if (styleProperty.getVerticalAlignment() != null) { + writeCellStyle.setVerticalAlignment(styleProperty.getVerticalAlignment()); + } + if (styleProperty.getRotation() != null) { + writeCellStyle.setRotation(styleProperty.getRotation()); + } + if (styleProperty.getIndent() != null) { + writeCellStyle.setIndent(styleProperty.getIndent()); + } + if (styleProperty.getBorderLeft() != null) { + writeCellStyle.setBorderLeft(styleProperty.getBorderLeft()); + } + if (styleProperty.getBorderRight() != null) { + writeCellStyle.setBorderRight(styleProperty.getBorderRight()); + } + if (styleProperty.getBorderTop() != null) { + writeCellStyle.setBorderTop(styleProperty.getBorderTop()); + } + if (styleProperty.getBorderBottom() != null) { + writeCellStyle.setBorderBottom(styleProperty.getBorderBottom()); + } + if (styleProperty.getLeftBorderColor() != null) { + writeCellStyle.setLeftBorderColor(styleProperty.getLeftBorderColor()); + } + if (styleProperty.getRightBorderColor() != null) { + writeCellStyle.setRightBorderColor(styleProperty.getRightBorderColor()); + } + if (styleProperty.getTopBorderColor() != null) { + writeCellStyle.setTopBorderColor(styleProperty.getTopBorderColor()); + } + if (styleProperty.getBottomBorderColor() != null) { + writeCellStyle.setBottomBorderColor(styleProperty.getBottomBorderColor()); + } + if (styleProperty.getFillPatternType() != null) { + writeCellStyle.setFillPatternType(styleProperty.getFillPatternType()); + } + if (styleProperty.getFillBackgroundColor() != null) { + writeCellStyle.setFillBackgroundColor(styleProperty.getFillBackgroundColor()); + } + if (styleProperty.getFillForegroundColor() != null) { + writeCellStyle.setFillForegroundColor(styleProperty.getFillForegroundColor()); + } + if (styleProperty.getShrinkToFit() != null) { + writeCellStyle.setShrinkToFit(styleProperty.getShrinkToFit()); + } + } }