3

I am currently using HSSFColor/HSSFPalette and XSSFColor to set the Existing/Custom Colors. Implementation is as follows : for e.g. font.setColor(HSSFColor.WHITE.index); for HSSF or cs.setFillForegroundColor(xssfColor); for XSSF

I want to pass parameters in both the above cases for "Hexadecimal Color Codes".

Like : for HSSF: font.setColor()/font.setColor(getShortIndexFromHexColorCodes()) for XSSF: cs.setFillForegroundColor();

Is there any way out to do the above thing, where I can pass Hexadecimal Color Code and the colors are applied in HSSF and XSSF.

Please guide me and thanks in advance:)

sidd
  • 31
  • 1
  • 1
  • 3

1 Answers1

7

When it comes to code examples, try here.

Now a slight explanation. In the case of font.setColor(short) the parameter is an index to a spot in the standard palette. By working with HSSFPalette, you can can call setColorAtIndex which takes four parameters. The first is an existing index spot in the default thread (meaning the existing color you will replace). The other three are red, green and blue values respectively for the color you want. Therefore, replacing a spot in the default palette with your custom creating will allow you to use your own hexadecimal values. This is the HSSF case.

The XSSF case really is trivial and here is an example setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128))) You don't have to make the same sacrifice that you have to make in HSSF. Just create that Color object with your required hex values for R, G and B

demongolem
  • 9,474
  • 36
  • 90
  • 105