From da1abea6b9de9da8b680b7bc384da6c0fb7bfac9 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 14 Jul 2015 21:10:14 +0000 Subject: [PATCH] Support unsetting the XSSF CF pattern colours git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691081 13f79535-47bb-0310-9956-ffa450edef68 --- .../xssf/usermodel/XSSFPatternFormatting.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java index 75989f3e79..3ca68f2bae 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java @@ -64,30 +64,40 @@ public class XSSFPatternFormatting implements PatternFormatting { public void setFillBackgroundColor(Color bg) { XSSFColor xcolor = XSSFColor.toXSSFColor(bg); - setFillBackgroundColor(xcolor.getCTColor()); + if (xcolor == null) setFillBackgroundColor((CTColor)null); + else setFillBackgroundColor(xcolor.getCTColor()); } public void setFillBackgroundColor(short bg) { CTColor bgColor = CTColor.Factory.newInstance(); bgColor.setIndexed(bg); setFillBackgroundColor(bgColor); } - public void setFillBackgroundColor(CTColor color) { + private void setFillBackgroundColor(CTColor color) { CTPatternFill ptrn = _fill.isSetPatternFill() ? _fill.getPatternFill() : _fill.addNewPatternFill(); - ptrn.setBgColor(color); + if (color == null) { + ptrn.unsetBgColor(); + } else { + ptrn.setBgColor(color); + } } public void setFillForegroundColor(Color fg) { XSSFColor xcolor = XSSFColor.toXSSFColor(fg); - setFillForegroundColor(xcolor.getCTColor()); + if (xcolor == null) setFillForegroundColor((CTColor)null); + else setFillForegroundColor(xcolor.getCTColor()); } public void setFillForegroundColor(short fg) { CTColor fgColor = CTColor.Factory.newInstance(); fgColor.setIndexed(fg); setFillForegroundColor(fgColor); } - public void setFillForegroundColor(CTColor color) { + private void setFillForegroundColor(CTColor color) { CTPatternFill ptrn = _fill.isSetPatternFill() ? _fill.getPatternFill() : _fill.addNewPatternFill(); - ptrn.setFgColor(color); + if (color == null) { + ptrn.unsetFgColor(); + } else { + ptrn.setFgColor(color); + } } public void setFillPattern(short fp){ -- 2.39.5