Bug 51469

Summary: XSSFRow.setRowStyle not implemented
Product: POI Reporter: Alexander <hoernlein>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: extraced xlsxs 'a' & 'b'

Description Alexander 2011-07-04 08:53:27 UTC
Created attachment 27249 [details]
extraced xlsxs 'a' & 'b'

for HSSFRow there is setRowStyle method, XSSFRow lacks this method.

attached you'll find extracted xlsx a & b, the differing files are xl/worksheets/sheet1.xml resp.. in both files there is a '1' in cell A1, which has a certain format (bottom border black thin). in file 'b' the 1st row additionally has the same format set as row format.

the differing part is:

<row r="1" spans="1:1">
vs.
<row r="1" spans="1:1" 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()) { // + maybe something like: "|| _row.isSetCustomFormat()"
                _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 (as it's only a pointer to row.getSheet().getWorkbook().getStylesSource()).
Comment 1 Nick Burch 2011-07-08 14:58:49 UTC
Thanks for this investigating. I've added support for setting row styles to XSSF and SXSSF in r1144348, along with unit tests. I've also promoted the getter and setter to the Row interface