<changes>
<release version="3.8-beta3" date="2011-??-??">
+ <action dev="poi-developers" type="fix">51236 - XSSF set colour support for black/white to match getter</action>
<action dev="poi-developers" type="add">51196 - Initial support for Spreadsheet Chart API</action>
<action dev="poi-developers" type="add">Add support for OOXML Agile Encryption</action>
<action dev="poi-developers" type="add">51160 - Initial version of SXSSF, a low memory foortprint API to produce xlsx files</action>
public void setIndexed(int indexed) {
ctColor.setIndexed(indexed);
}
+
+ /**
+ * For RGB colours, but not ARGB (we think...)
+ * Excel gets black and white the wrong way around, so switch them
+ */
+ private byte[] correctRGB(byte[] rgb) {
+ if(rgb.length == 4) {
+ // Excel doesn't appear to get these wrong
+ // Nothing to change
+ return rgb;
+ } else {
+ // Excel gets black and white the wrong way around, so switch them
+ if (rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0) {
+ rgb = new byte[] {-1, -1, -1};
+ }
+ else if (rgb[0] == -1 && rgb[1] == -1 && rgb[2] == -1) {
+ rgb = new byte[] {0, 0, 0};
+ }
+ return rgb;
+ }
+ }
/**
* Standard Red Green Blue ctColor value (RGB).
// Grab the colour
rgb = ctColor.getRgb();
- if(rgb.length == 4) {
- // Good to go, return it as-is
- return rgb;
- }
-
- // For RGB colours, but not ARGB (we think...)
- // Excel gets black and white the wrong way around, so switch them
- if (rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0) {
- rgb = new byte[] {-1, -1, -1};
- }
- else if (rgb[0] == -1 && rgb[1] == -1 && rgb[2] == -1) {
- rgb = new byte[] {0, 0, 0};
- }
- return rgb;
+ // Correct it as needed, and return
+ return correctRGB(rgb);
}
/**
* Standard Alpha Red Green Blue ctColor value (ARGB).
*/
public void setRgb(byte[] rgb) {
- ctColor.setRgb(rgb);
+ // Correct it and save
+ ctColor.setRgb(correctRGB(rgb));
}
-
+
/**
* Index into the <clrScheme> collection, referencing a particular <sysClr> or
* <srgbClr> value expressed in the Theme part.
assertEquals(0, rgb3.getRgbWithTint()[0]);
assertEquals(0, rgb3.getRgbWithTint()[1]);
assertEquals(0, rgb3.getRgbWithTint()[2]);
+
+ // Set the colour to black, will get translated internally
+ // (Excel stores 3 colour white and black wrong!)
+ rgb3.setRgb(new byte[] {-1,-1,-1});
+ assertEquals("FFFFFFFF", rgb3.getARGBHex());
+ assertEquals(0, rgb3.getCTColor().getRgb()[0]);
+ assertEquals(0, rgb3.getCTColor().getRgb()[1]);
+ assertEquals(0, rgb3.getCTColor().getRgb()[2]);
+
+ // Set another, is fine
+ rgb3.setRgb(new byte[] {16,17,18});
+ assertEquals("FF101112", rgb3.getARGBHex());
+ assertEquals(0x10, rgb3.getCTColor().getRgb()[0]);
+ assertEquals(0x11, rgb3.getCTColor().getRgb()[1]);
+ assertEquals(0x12, rgb3.getCTColor().getRgb()[2]);
}
public void testARGBColour() throws Exception {