View | Details | Raw Unified | Return to bug 60898
Collapse All | Expand All

(-)XSSFColor.java (-1 / +35 lines)
Lines 23-28 Link Here
23
import org.apache.poi.ss.usermodel.IndexedColors;
23
import org.apache.poi.ss.usermodel.IndexedColors;
24
import org.apache.poi.util.Internal;
24
import org.apache.poi.util.Internal;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
26
import org.w3c.dom.DOMException;
27
import org.w3c.dom.Element;
28
import org.w3c.dom.Node;
29
import org.w3c.dom.NodeList;
26
30
27
/**
31
/**
28
 * Represents a color in SpreadsheetML
32
 * Represents a color in SpreadsheetML
Lines 159-165 Link Here
159
      }
163
      }
160
   }
164
   }
161
165
162
   /**
166
   @Override
167
protected byte[] getRGBOrARGB() {
168
		if (isIndexed()) {
169
			try {
170
				Node parentNode = ctColor.getDomNode().getParentNode();
171
				while (parentNode.getNodeName().trim() != "styleSheet") {
172
					parentNode = parentNode.getParentNode();
173
				}
174
				Node colorsNode = ((Element) parentNode).getElementsByTagName("colors").item(0);
175
				Node indexedColorsNode = colorsNode.getFirstChild().getChildNodes().item(getIndex());
176
				String hexString = indexedColorsNode.getAttributes().getNamedItem("rgb").getNodeValue();
177
				return hexStringToByteArray(hexString);
178
			} catch (Exception e) {
179
				return super.getRGBOrARGB();
180
			}
181
		}
182
		return super.getRGBOrARGB();
183
}
184
   
185
  private byte[] hexStringToByteArray(String s) {
186
	    byte[] b = new byte[s.length() / 2];
187
	    for (int i = 0; i < b.length; i++) {
188
	      int index = i * 2;
189
	      int v = Integer.parseInt(s.substring(index, index + 2), 16);
190
	      b[i] = (byte) v;
191
	    }
192
	    return b;
193
	  }
194
195
196
/**
163
    * Standard Alpha Red Green Blue ctColor value (ARGB).
197
    * Standard Alpha Red Green Blue ctColor value (ARGB).
164
    */
198
    */
165
   @Override
199
   @Override

Return to bug 60898