• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to apply custom colors for HSSF Workbook

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I have to apply custom colors to Excel cells of HSSF Workbook. I have created cell style like but it is not applying expected clor

HSSFWorkbook hssfwb = (HSSFWorkbook)wb;
HSSFPalette palette = hssfwb.getCustomPalette();
short colorIndex = 45;
palette.setColorAtIndex(colorIndex, (byte)201, (byte)221, (byte)255);
CellStyle style = wb.createCellStyle();
style.setFillForegroundColor(colorIndex);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
return style;
Please help me on this.

Thanks,
ypk
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I suspect that your problem is here : HSSFWorkbook hssfwb = (HSSFWorkbook)wb;

You define your style for hssfwb but you try to apply it on wb but these are two different objects

Try something like this :



 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Oliver,

Thanks, for your response.
But not worked out.

Is there any way to apply custom clors to cexcel cells with POI.

Thanks,
ypk
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need to supply more details for us to help you. Start by posting an SSCCE (<- that's a iink).
 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have requirement to apply colors to headers in Excel Report. I am poi 3.8v to create cells and applying styles.
In the below fashion I have created style and callingwhen ever required. But it is not working .

private static CellStyle setThinBorder_NoneColor(Workbook wb, DataFormat df) {

HSSFWorkbook hssfwb = (HSSFWorkbook)wb;
HSSFPalette palette = hssfwb.getCustomPalette();
short colorIndex = 45;
palette.setColorAtIndex(colorIndex, (byte)201, (byte)221, (byte)255);
HSSFCellStyle style = ((HSSFWorkbook)wb).createCellStyle();
style.setFillForegroundColor(colorIndex);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
return style;
}

Can anyone help me how to apply custom colors with POI.

Thanks,
ypk
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks pretty much like the code you posted before, but it's not an SSCCE. The easier you make it for folks here to reproduce your problem, the likelier it is that someone will try to help. (If you post an SSCCE, I promise to run it and try to understand what's happening.)
 
Olivier Rihoux
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please, try replacing



by

 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Olivier,

I have tried with the given sample piece, but not working.

Please help me.


Thanks,
ypk
 
Olivier Rihoux
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to help more, i need not only the procedure returning thez style but also the main code where you use it
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:That looks pretty much like the code you posted before, but it's not an SSCCE. The easier you make it for folks here to reproduce your problem, the likelier it is that someone will try to help. (If you post an SSCCE, I promise to run it and try to understand what's happening.)

 
Praveen Yendluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

My prolem was solved. Sample code below

HSSFCellStyle style = ((HSSFWorkbook)wb).createCellStyle();
HSSFPalette palette = ((HSSFWorkbook)wb).getCustomPalette();
palette.setColorAtIndex((short)57, (byte)255, (byte)228, (byte)225);
style.setFillForegroundColor(palette.getColor(57).getIndex());
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

Thanks very much everyone for your kind help.

Regards,
ypk
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic