From: Nick Burch Date: Fri, 18 Feb 2011 16:44:05 +0000 (+0000) Subject: Fix bug #50299 with patch from Andrei - Fix XSSFColor fetching of white and black... X-Git-Tag: REL_3_8_BETA1~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1b354bc434ee9e3b08bc871a9109a06e16b70034;p=poi.git Fix bug #50299 with patch from Andrei - Fix XSSFColor fetching of white and black background themes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1072053 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 44524a32ae..fbcb3cc42e 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50299 - Fix XSSFColor fetching of white and black background themes 50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another 46664 - When creating HSSF Print Areas, ensure the named range is reference based not value based 50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General diff --git a/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java index d78e31073f..5b8b228691 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java @@ -51,7 +51,17 @@ public class ThemesTable extends POIXMLDocumentPart { if (obj instanceof org.openxmlformats.schemas.drawingml.x2006.main.CTColor) { if (cnt == idx) { ctColor = (org.openxmlformats.schemas.drawingml.x2006.main.CTColor) obj; - return new XSSFColor(ctColor.getSrgbClr().getVal()); + + byte[] rgb = null; + if (ctColor.getSrgbClr() != null) { + // Colour is a regular one + rgb = ctColor.getSrgbClr().getVal(); + } else if (ctColor.getSysClr() != null) { + // Colour is a tint of white or black + rgb = ctColor.getSysClr().getLastClr(); + } + + return new XSSFColor(rgb); } cnt++; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 9f8909ea61..349ab9bd8b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -673,6 +673,37 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals(exp, comment.getString().getString()); } + /** + * When the cell background colour is set with one of the first + * two columns of the theme colour palette, the colours are + * shades of white or black. + * For those cases, ensure we don't break on reading the colour + */ + public void test50299() throws Exception { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50299.xlsx"); + + // Check all the colours + for(int sn=0; sn