Of course. It's a little complicated to extract the relevant lines of code,
because it's part of a framework. But I'll try:
private HSSFColor evenRowColor;
//...
public XLSTablePartFormatter(final TableFormatDefinition tfd) {
//...
evenRowColor = getColor(tfd.getEvenRowColor());
}
public HSSFCellStyle getTextCellStyleBright(HSSFCellStyle cellStyle) {
cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
cellStyle = getTextCellStyle(cellStyle);
cellStyle.setFillBackgroundColor(evenRowColor.getIndex());
return cellStyle;
}
//...
protected HSSFCellStyle getTextCellStyle(HSSFCellStyle cellStyle) {
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
return cellStyle;
}
This class formats data in XLS style according to a table definition. The
method 'tfd.getEvenRowColor()' returns the HSSFColor - as converted by the
getColor(final Color col) method from my first mail.
Claus
-----Ursprüngliche Nachricht-----
Von: Tom Schindl [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 26. Januar 2006 11:30
An: POI Users List
Betreff: Re: Excel colors
Could you post the code how you are setting the background color on a cell?
Tom
Claus Luethje wrote:
> Hi,
> I build an excel sheet with colored cells and texts, and it works fine
> when I use the predefined colors. But when I add colors myself, I get
> grey scale colors. Do I have to change some settings in the Workbook
> (or anywhere else)?
>
> I set the palette and colors like this:
>
> private HSSFPalette palette = new HSSFPalette(new
> PaletteRecord((short)0x92)){};
>
> protected final HSSFColor getColor(final Color col){
> HSSFColor c;
> c = palette.findColor((byte)col.getRed(), (byte)col.getGreen(),
> (byte)col.getBlue());
> if(c==null){
> try{
> c = palette.addColor((byte)col.getRed(),
> (byte)col.getGreen(), (byte)col.getBlue());
> } catch (RuntimeException re){
> c = palette.findSimilarColor((byte)col.getRed(),
> (byte)col.getGreen(), (byte)col.getBlue());
> }
> }
> return c;
> }
>
> Thanks for your help!
>
> Regards,
> Claus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List: http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/