]> source.dussan.org Git - poi.git/commitdiff
Test to show that bug #45492 is invalid
authorNick Burch <nick@apache.org>
Sun, 21 Sep 2008 18:56:32 +0000 (18:56 +0000)
committerNick Burch <nick@apache.org>
Sun, 21 Sep 2008 18:56:32 +0000 (18:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@697584 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
src/testcases/org/apache/poi/hssf/data/45492.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 2afd16d8d1bdae7b4e97c808fa51ba068f19412f..d71619aaa8563e4b7feaedeccb3df2a65bc19b86 100644 (file)
@@ -913,7 +913,9 @@ public class HSSFCellStyle
     }
 
     /**
-     * get the background fill color
+     * Get the background fill color.
+     * Note - many cells are actually filled with a foreground
+     *  fill, not a background fill - see {@link #getFillForegroundColor()}
      * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
      * @return fill color
      */
@@ -939,7 +941,9 @@ public class HSSFCellStyle
     }
 
     /**
-     * get the foreground fill color
+     * Get the foreground fill color.
+     * Many cells are filled with this, instead of a 
+     *  background color ({@link #getFillBackgroundColor()})
      * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
      * @return fill color
      */
index 8674904d0c14519403d66b0217dacf2e16bc4168..4c9d63ebc471db7bf26845ba61a90808b1d50331 100644 (file)
@@ -57,6 +57,15 @@ public class HSSFPalette
        }
         return null;
     }
+    /**
+     * Retrieves the color at a given index
+     *
+     * @param index the palette index, between 0x8 to 0x40 inclusive
+     * @return the color, or null if the index is not populated
+     */
+    public HSSFColor getColor(int index) {
+       return getColor((short)index);
+    }
     
     /**
      * Finds the first occurance of a given color
diff --git a/src/testcases/org/apache/poi/hssf/data/45492.xls b/src/testcases/org/apache/poi/hssf/data/45492.xls
new file mode 100644 (file)
index 0000000..7e044e8
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45492.xls differ
index cc3bf573d2d24a2bfdea266d9851a313996a11c4..ea807f0542f92f4469f34c39efd0cb7c389d7bd5 100644 (file)
@@ -1482,6 +1482,41 @@ public final class TestBugs extends TestCase {
        // This used to break
         HSSFWorkbook wb = openSample("45784.xls");
         assertEquals(1, wb.getNumberOfSheets());
+    }
+    
+   /**
+     * Cell background colours
+     */
+    public void test45492() {
+       HSSFWorkbook wb = openSample("45492.xls");
+       HSSFSheet s = wb.getSheetAt(0);
+       HSSFRow r = s.getRow(0);
+       HSSFPalette p = wb.getCustomPalette();
+       
+       HSSFCell auto = r.getCell(0);
+       HSSFCell grey = r.getCell(1);
+       HSSFCell red = r.getCell(2);
+       HSSFCell blue = r.getCell(3);
+       HSSFCell green = r.getCell(4);
+       
+       assertEquals(64, auto.getCellStyle().getFillForegroundColor());
+       assertEquals(64, auto.getCellStyle().getFillBackgroundColor());
+       assertEquals("0:0:0", p.getColor(64).getHexString());
+       
+       assertEquals(22, grey.getCellStyle().getFillForegroundColor());
+       assertEquals(64, grey.getCellStyle().getFillBackgroundColor());
+       assertEquals("C0C0:C0C0:C0C0", p.getColor(22).getHexString());
+       
+       assertEquals(10, red.getCellStyle().getFillForegroundColor());
+       assertEquals(64, red.getCellStyle().getFillBackgroundColor());
+       assertEquals("FFFF:0:0", p.getColor(10).getHexString());
+       
+       assertEquals(12, blue.getCellStyle().getFillForegroundColor());
+       assertEquals(64, blue.getCellStyle().getFillBackgroundColor());
+       assertEquals("0:0:FFFF", p.getColor(12).getHexString());
        
+       assertEquals(11, green.getCellStyle().getFillForegroundColor());
+       assertEquals(64, green.getCellStyle().getFillBackgroundColor());
+       assertEquals("0:FFFF:0", p.getColor(11).getHexString());
     }
 }