short blue = Short.parseShort(color.substring(5), 16); //blue
byte r = (byte)Math.abs((byte)red);
byte g = (byte)Math.abs((byte)green);
byte b = (byte)Math.abs((byte)blue);
HSSFColor pcolor = palette.findColor(r, g, b);
if (pcolor != null) { //find default palette
return pcolor.getIndex();
} else {
final Hashtable<short[], HSSFColor> colors = HSSFColor.getRgbHash();
HSSFColor tcolor = colors.get(new short[] {red, green, blue});
if (tcolor != null)
return tcolor.getIndex();
else {
try {
HSSFColor ncolor = palette.addColor(r, g, b);
return ncolor.getIndex();
} catch (RuntimeException ex) {
//return similar color if can't add new color to palette
/*
* TODO: find a better solution for fix this issue
*