Keep me up-to-date if it doesn't work I'll send you a real working program which I know is working on my Desktop.
Tom Claus Luethje wrote: > Thanks for the code snipplet. > Another difference seems to be that you keep a map to find your named colors, > while I use the index. > I'll try the named colors approach. > > Claus > > -----Ursprüngliche Nachricht----- > Von: Tom Schindl [mailto:[EMAIL PROTECTED] > Gesendet: Donnerstag, 26. Januar 2006 13:00 > An: Claus Luethje; POI Users List > Betreff: Re: AW: AW: Excel colors > > Please always keep the list CC. > > Well there are 2 differences between us: > - I create the palette from the workbook > - I'm replacing colors while you are adding them to the Palette and my > code looks like the following: > > ---------------------8<-------------------- > HSSFWorkbook workbook = new HSSFWorkbook(); HSSFPalette p = > workbook.getCustomPalette(); HashMap<String,Short> map = new > HashMap<String,Short>(); short i = 10; > > p.setColorAtIndex( ++i, (byte)255, (byte)0, (byte)0 ); map.put( "myRed", i ); > > p.setColorAtIndex( ++i, (byte)255, (byte)255, (byte)0 ); map.put( "myYellow", > i ); > > HSSFStyle style = workbook.createStyle(); style.setFillForegroundColor( > map.get("myRed") ); style.setFillPattern( HSSFCellStyle.SOLID_FOREGROUND ); > > HSSFRow row = workbook.createRow((short)0); cell = row.createCell((short)0); > cell.setCellStyle(style); > ---------------------8<-------------------- > > Tom > > Claus Luethje wrote: > >>Tom, >>I changed setBackgroundColor() to setForegroundColor(), that led to different >>colors (but still black and white). >>HSSFStyle seems not to be defined. I just have HSSFCellStyle. >>Is the order the setForeground() and setFillPattern() relevant? >> >>Claus >> >>-----Ursprüngliche Nachricht----- >>Von: Tom Schindl [mailto:[EMAIL PROTECTED] >>Gesendet: Donnerstag, 26. Januar 2006 12:37 >>An: POI Users List; Claus Luethje >>Betreff: Re: AW: Excel colors >> >>Ok and here's the 'fault', This should be better documented in the API-Docs >>and examples found on the poi-page: >> >>------------8<------------ >>style.setForegroundColor( evenRowColor.getIndex() ); >>style.setFillPattern( HSSFStyle.SOLID_FOREGROUND ); >>------------8<------------ >> >>And you are done ;-) >> >>Tom >> >> >>Claus Luethje wrote: >> >> >>>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/ >>> >>> >> >> >> >> > > > > --------------------------------------------------------------------- > 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/ > >
signature.asc
Description: OpenPGP digital signature
