Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making new colors in JExcelApi

I'm using JExcelApi for generating XLS files. From jxl.format.Colour, I see how to get any of the colors in the "standard Excel colour palette", but not how to create a new color (say, given its RGB).

But in Excel itself, I can pick any color at all.

Am I just missing it? Is there a way in JExcelApi to select an arbitrary color? I'm using a simple find-the-closest-standard-color method right now, which is OK but not great.

like image 654
Ken Avatar asked Dec 02 '09 18:12

Ken


1 Answers

The way to override a palette index in JExcel API is to use the method [setColourRGB][1] on the writable workbook. For instance:

myWorkbook.setColourRGB(Colour.LIGHT_TURQUOISE2, 14, 67, 89);

if you want to change the color value in the palette entry where there is by default the second light turquoise. Or, more easily in some cases, directly with the palette index:

myWorkbook.setColourRGB(Colour.getInternalColour(myPaletteIdx), 14, 67, 89);

A small update: only the indexes from 8 to 64 can be customized according to a comment inside the source code of jxl.biff.PaletteRecord.

[1]: http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/jxl/write/WritableWorkbook.html#setColourRGB(jxl.format.Colour, int, int, int)

like image 176
Damien B Avatar answered Oct 28 '22 07:10

Damien B