I'm trying to set Excel cell colors using Apache POI in Java. I played ar开发者_StackOverflowound in Excel itself and chose the colors I wanted - but I can't figure out how to use those colors with POI. I'm using the font.setColor
method, which takes a short that's the index of a color... Which seems to indicate that I'm limited to the constants in IndexedColors
. Is there any way to set a cell to a hex color value? Or can I only use the predefined constants?
You can use the HSSFPalette
class to query the defined colors and define your own colors as well (using setColorAtIndex()
).
I'm working with HWPF, not HSSF and I'm too lazy to go looking, but do the cell/character format classes you're working with have an attribute named "ico24" or something similar? In HWPF, that's the int
representation of a 24 bit (A)RGB color spec which can be used to specify any color you like.
精彩评论