|Summary:||[RFE] Setting background color for entire row|
|Product:||POI||Reporter:||Calvin Cheung <calvin>|
|Component:||HSSF||Assignee:||POI Developers List <dev>|
[PATCH] allows setting the style for the entire row
[PATCH] allows setting and retrieving style for entire row
Description Calvin Cheung 2003-02-10 18:08:13 UTC
A method can be added to the HSSFRow class to set the background color for a particular row. public void setBackgroundColor(short colorIndex); Thanks in advance.
Comment 1 Andy Oliver 2003-02-10 18:34:23 UTC
Comment 2 Avik Sengupta 2005-05-20 11:43:46 UTC
Anybody have an idea how to do this? Does row record have a relevant field?
Comment 3 Amol Deshmukh 2005-05-20 18:01:09 UTC
Created attachment 15091 [details] [PATCH] allows setting the style for the entire row There is an ExtendedFormatRecord for the RowRecord corresponding to HSSFRow instance. The user api did not allow a way to set this. Thus 2 functions have been added to HSSFRow: set/getRowStyle(HSSFCellStyle) to enable this. TestCases included (based on test cases for HSSFCellStyle)
Comment 4 Avik Sengupta 2005-05-20 19:12:27 UTC
Thanks Amol, that was impressively fast... but it doesnt seem the patch will read in an existing style from a workbook. I think the HSSFRow should not keep a reference to HSSFStyle, rather construct it on demand from the XF record. That should allow returning existing styles. How does HSSFCell.getCellStyle() work?
Comment 5 Amol Deshmukh 2005-05-20 20:30:19 UTC
Created attachment 15095 [details] [PATCH] allows setting and retrieving style for entire row Doh! thanks for pointing that out! Now the rowStyle is initialized in the constructor (a la HSSFCell :) Modified the test case to show that retrieving works.
Comment 6 Rickard B 2008-09-16 06:58:25 UTC
(In reply to comment #5) > Created an attachment (id=15095) [details] > [PATCH] allows setting and retrieving style for entire row > > Doh! thanks for pointing that out! Now the rowStyle is initialized in the > constructor (a la HSSFCell :) Modified the test case to show that retrieving > works. I tried your patch and it successfully reads the data in. But when I write it back it doesn't get saved. If you use this: ExtendedFormatRecord xf = book.workbook.getExFormatAt(record.getXFIndex()); setRowStyle(new HSSFCellStyle(( short ) record.getXFIndex(), xf, book)); instead of + ExtendedFormatRecord xf = book.getExFormatAt(record.getXFIndex()); + setRowStyle(new HSSFCellStyle(( short ) 0xf, xf)) in the constructor for HSSFRow write back will also work. Thanks
Comment 7 Nick Burch 2008-09-21 14:39:36 UTC
Patch applied to svn trunk, with a few slight tweaks to make it more HSSFCell like. Test applied too. Thanks