https://bz.apache.org/bugzilla/show_bug.cgi?id=60898

--- Comment #5 from samson <[email protected]> ---
Comment on attachment 34865
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34865
solution 2 (partial)

Index: XSSFColor.java
===================================================================
--- XSSFColor.java      (revision 293556)
+++ XSSFColor.java      (working copy)
@@ -23,6 +23,9 @@
 import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.util.Internal;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColors;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRgbColor;
+import org.w3c.dom.DOMException;

 /**
  * Represents a color in SpreadsheetML
@@ -29,6 +32,7 @@
  */
 public class XSSFColor extends ExtendedColor {
     private final CTColor ctColor;
+    private CTColors indexedColors;

     /**
      * Create an instance of XSSFColor from the supplied XML bean
@@ -36,6 +40,11 @@
     public XSSFColor(CTColor color) {
         this.ctColor = color;
     }
+    
+    public XSSFColor(CTColors indexedColors, CTColor color){
+       this.indexedColors = indexedColors;
+       this.ctColor = color;
+    }

     /**
      * Create an new instance of XSSFColor
@@ -179,6 +188,38 @@
          return rgb;
       }
    }
+   
+   @Override
+   protected byte[] getRGBOrARGB() throws DOMException{
+          if(isIndexed() && hasCustomIndexedColors()){
+                  CTRgbColor ctRgbColor = indexedColors.getIndexedColors().
+                                  getRgbColorList().get(getIndexed());
+                  String hexString =
ctRgbColor.getDomNode().getAttributes().getNamedItem("rgb").getNodeValue();
+                  return hexStringToByteArray(hexString);
+          }
+          return super.getRGBOrARGB();
+   }
+   
+   private boolean hasCustomIndexedColors(){
+      
+       if (indexedColors == null) {
+           return false;
+       }
+       if (indexedColors.getIndexedColors() == null) {
+           return false;
+       }
+       return true;
+   }
+   
+   private byte[] hexStringToByteArray(String s) {
+           byte[] b = new byte[s.length() / 2];
+           for (int i = 0; i < b.length; i++) {
+             int index = i * 2;
+             int v = Integer.parseInt(s.substring(index, index + 2), 16);
+             b[i] = (byte) v;
+           }
+           return b;
+         }

    @Override
    protected byte[] getStoredRBG() {

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to