]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50299 with patch from Andrei - Fix XSSFColor fetching of white and black...
authorNick Burch <nick@apache.org>
Fri, 18 Feb 2011 16:44:05 +0000 (16:44 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Feb 2011 16:44:05 +0000 (16:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1072053 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/50299.xlsx [new file with mode: 0644]

index 44524a32ae4203707dc9288689df7ad0365e05ef..fbcb3cc42e6eaff4c9d063ffff11f3549fb3dd22 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="poi-developers" type="fix">50299 - Fix XSSFColor fetching of white and black background themes</action>
            <action dev="poi-developers" type="fix">50795 - Avoid NPE from xmlbeans when moving XSSF Comments from one cell to another</action>
            <action dev="poi-developers" type="fix">46664 - When creating HSSF Print Areas, ensure the named range is reference based not value based</action>
            <action dev="poi-developers" type="fix">50756 - When formatting numbers based on their Cell Style, treat GENERAL the same as the more typical General</action>
index d78e31073f5de15634762dadf2c6a80b5b7fa164..5b8b2286914abf5cf35d43119d4694825d2bab03 100644 (file)
@@ -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++;
             }
index 9f8909ea612fa9d7f9465cd4710e0cd0a1f71201..349ab9bd8b62e8d97c86d92b93bfb0e9f886c2a7 100644 (file)
@@ -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<wb.getNumberOfSheets(); sn++) {
+          Sheet s = wb.getSheetAt(sn);
+          for(Row r : s) {
+             for(Cell c : r) {
+                CellStyle cs = c.getCellStyle();
+                if(cs != null) {
+                   cs.getFillForegroundColor();
+                }
+             }
+          }
+       }
+       
+       // Check one bit in detail
+       // TODO Is this correct, shouldn't one be white and one black?
+       Sheet s = wb.getSheetAt(0);
+       assertEquals(0,  s.getRow(0).getCell(8).getCellStyle().getFillForegroundColor());
+       assertEquals(64, s.getRow(0).getCell(8).getCellStyle().getFillBackgroundColor());
+       assertEquals(0,  s.getRow(1).getCell(8).getCellStyle().getFillForegroundColor());
+       assertEquals(64, s.getRow(1).getCell(8).getCellStyle().getFillBackgroundColor());
+    }
+    
     /**
      * Fonts where their colours come from the theme rather
      *  then being set explicitly still should allow the
diff --git a/test-data/spreadsheet/50299.xlsx b/test-data/spreadsheet/50299.xlsx
new file mode 100644 (file)
index 0000000..7a1acf3
Binary files /dev/null and b/test-data/spreadsheet/50299.xlsx differ