You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Alexander Hörnlein <ho...@uni-wuerzburg.de> on 2011/06/21 11:13:20 UTC

HSSFRow.setRowStyle -> XSSFRow.??? <- no such method

Hi all,

we are just "upgrading" from HSSF to XSSF (because we need more 
columns). We use sometimes HSSFRow.setRowStyle for formatting, because 
there are null Cells which we don't want to create just to be able to 
apply a CellStyle. Now, in Row and XSSFRow, there is no such method. How 
can we recreate the behaviour from our old version? Or will this be 
method be reimplemented antime? If yes, when is it planned?

Cheers,

Alexander


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: HSSFRow.setRowStyle -> XSSFRow.??? <- no such method

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 28 Jun 2011, Alexander Hörnlein wrote:
> ok - i created a xlsx with the style of the first row + the first cell 
> set to the same style and another one where only the first cell has the 
> style and the only difference was
>
> <row ...> ...
> vs.
> <row ... s="1" customFormat="1">....

Looks like it it's similar to cells, handy. Any chance you could create a 
new bug in bugzilla, and upload a sample file which we can use in a unit 
test?

> so i guess the code from XSSFCell should work for XSSFRow (+ customFormat), 
> so it should be something like:
>
>    public void setCellStyle(CellStyle style) {
>        if(style == null) {
>            if(_row.isSetS()) {
>                _row.unsetS();
>                _row.unsetCustomFormat();
>        } else {
>            XSSFCellStyle xStyle = (XSSFCellStyle)style;
>            xStyle.verifyBelongsToStylesSource(_stylesSource);
>
>            long idx = _stylesSource.putStyle(xStyle);
>            _row.setS(idx);
>            _row.setCustomFormat(true);
>        }
>    }
>
> the _stylesSource of XSSFRow could be handled exactly like for XSSFCell 
> (it's only a pointer to row.getSheet().getWorkbook().getStylesSource();

Looks correct. Please include this in the bug report, and I'll have a go 
at writing a unit test for it, and I'll then commit it for you

Cheers
Nick

Re: HSSFRow.setRowStyle -> XSSFRow.??? <- no such method

Posted by Alexander Hörnlein <ho...@uni-wuerzburg.de>.
Am 21.06.2011 22:08, schrieb Nick Burch:
> On Tue, 21 Jun 2011, Alexander Hörnlein wrote:
>> we are just "upgrading" from HSSF to XSSF (because we need more 
>> columns). We use sometimes HSSFRow.setRowStyle for formatting, 
>> because there are null Cells which we don't want to create just to be 
>> able to apply a CellStyle. Now, in Row and XSSFRow, there is no such 
>> method.
>
> It looks like that support still needs to be added.
>
> I'd suggest you create a very simple xlsx file in excel, with say one 
> row styled and one not. Next, unzip the file and compare the two rows 
> to see how the styling is set. Then, check the microsoft docs on those 
> xml elements and attributes to check. Finally, add getters and setters 
> that work with the xmlbeans objects wrapping those xml bits, likely 
> wrapping them in appropriate xssf usermodel classes
>
> If you get it working, please do send in a patch!
>
> Nick
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org

ok - i created a xlsx with the style of the first row + the first cell 
set to the same style and another one where only the first cell has the 
style and the only difference was

<row ...> ...
vs.
<row ... s="1" customFormat="1">....

so i guess the code from XSSFCell should work for XSSFRow (+ 
customFormat), so it should be something like:

     public void setCellStyle(CellStyle style) {
         if(style == null) {
             if(_row.isSetS()) {
                 _row.unsetS();
                 _row.unsetCustomFormat();
         } else {
             XSSFCellStyle xStyle = (XSSFCellStyle)style;
             xStyle.verifyBelongsToStylesSource(_stylesSource);

             long idx = _stylesSource.putStyle(xStyle);
             _row.setS(idx);
             _row.setCustomFormat(true);
         }
     }

the _stylesSource of XSSFRow could be handled exactly like for XSSFCell 
(it's only a pointer to row.getSheet().getWorkbook().getStylesSource();

-- 
alexander

Re: HSSFRow.setRowStyle -> XSSFRow.??? <- no such method

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 21 Jun 2011, Alexander Hörnlein wrote:
> we are just "upgrading" from HSSF to XSSF (because we need more 
> columns). We use sometimes HSSFRow.setRowStyle for formatting, because 
> there are null Cells which we don't want to create just to be able to 
> apply a CellStyle. Now, in Row and XSSFRow, there is no such method.

It looks like that support still needs to be added.

I'd suggest you create a very simple xlsx file in excel, with say one row 
styled and one not. Next, unzip the file and compare the two rows to see 
how the styling is set. Then, check the microsoft docs on those xml 
elements and attributes to check. Finally, add getters and setters that 
work with the xmlbeans objects wrapping those xml bits, likely wrapping 
them in appropriate xssf usermodel classes

If you get it working, please do send in a patch!

Nick