poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1072082 - in /poi/trunk: src/documentation/content/xdocs/ src/ooxml/java/org/apache/poi/xssf/usermodel/ src/ooxml/testcases/org/apache/poi/xssf/usermodel/ test-data/spreadsheet/
Date Fri, 18 Feb 2011 17:41:43 GMT
Author: nick
Date: Fri Feb 18 17:41:42 2011
New Revision: 1072082

URL: http://svn.apache.org/viewvc?rev=1072082&view=rev
Log:
Fix bug #50786 - Fix XSSFColor to fetch the RGB values of old-style indexed colours

Added:
    poi/trunk/test-data/spreadsheet/50786-indexed_colours.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1072082&r1=1072081&r2=1072082&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Feb 18 17:41:42 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="poi-developers" type="fix">50786 - Fix XSSFColor to fetch the
RGB values of old-style indexed colours</action>
            <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>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java?rev=1072082&r1=1072081&r2=1072082&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java Fri Feb 18 17:41:42
2011
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel;
 
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.Color;
 import org.apache.poi.util.Internal;
 
@@ -83,7 +84,22 @@ public class XSSFColor implements Color 
      * Standard Alpha Red Green Blue ctColor value (ARGB).
      */
     public byte[] getRgb() {
-		return ctColor.getRgb();
+       if(ctColor.isSetIndexed() && ctColor.getIndexed() > 0) {
+          HSSFColor indexed = HSSFColor.getIndexHash().get((int)ctColor.getIndexed());
+          if(indexed != null) {
+             // Convert it to ARGB form
+             byte[] rgb = new byte[4];
+             rgb[0] = 0;
+             rgb[1] = (byte)indexed.getTriplet()[0];
+             rgb[2] = (byte)indexed.getTriplet()[1];
+             rgb[3] = (byte)indexed.getTriplet()[2];
+             return rgb;
+          } else {
+             // Your indexed value isn't a standard one, sorry...
+             return null;
+          }
+       }
+		 return ctColor.getRgb();
 	}
 	
     /**
@@ -99,7 +115,7 @@ public class XSSFColor implements Color 
 	
 	/**
 	 * Return the ARGB value in hex format, eg FF00FF00.
-	 * For indexed colours, returns null.
+	 * Works for both regular and indexed colours. 
 	 */
 	public String getARGBHex() {
 	   StringBuffer sb = new StringBuffer();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1072082&r1=1072081&r2=1072082&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Fri Feb
18 17:41:42 2011
@@ -705,6 +705,26 @@ public final class TestXSSFBugs extends 
     }
     
     /**
+     * Excel .xls style indexed colours in a .xlsx file
+     */
+    public void test50786() throws Exception {
+       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50786-indexed_colours.xlsx");
+       XSSFSheet s = wb.getSheetAt(0);
+       XSSFRow r = s.getRow(2);
+       
+       // Check we have the right cell
+       XSSFCell c = r.getCell(1);
+       assertEquals("test\u00a0", c.getRichStringCellValue().getString());
+       
+       // It should be light green
+       XSSFCellStyle cs = c.getCellStyle();
+       assertEquals(42, cs.getFillForegroundColor());
+       assertEquals(42, cs.getFillForegroundColorColor().getIndexed());
+       assertNotNull(cs.getFillForegroundColorColor().getRgb());
+       assertEquals("00CCFFCC", cs.getFillForegroundColorColor().getARGBHex());
+    }
+    
+    /**
      * Fonts where their colours come from the theme rather
      *  then being set explicitly still should allow the
      *  fetching of the RGB 

Added: poi/trunk/test-data/spreadsheet/50786-indexed_colours.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/50786-indexed_colours.xlsx?rev=1072082&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/50786-indexed_colours.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message