Bug 57294

Summary: RichText is converted to nomal text in SXSSF
Product: POI Reporter: Conny Yuka <y-konishi>
Component: SXSSFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: major    
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on: 52972    
Bug Blocks:    

Description Conny Yuka 2014-12-02 10:45:08 UTC
I have used SXSSF to output Excel files (xlsx).
When I tried to write RichTextString in SXSSFCell, it was converted to normal text in output file,
(just reflected one cell style to whole cell),
because it seems that SheetDataWriter.java does not support RichTextString.

Then, I tried to change method SheetDataWriter#writeCell according to the rules of OOXML, 
and it worked well in my environment.

Here is my code:
-----------------------------------------
SheetDataWriter.java

public void writeCell(int columnIndex, Cell, cell) throws IOException {
    int celltype = cell.getCellType();
    switch(celltype){
    case Cell.CELL_TYPE_STRING:
        // get RichTextString info
        XSSFRichTextString richText = (XSSFRichTextString) cell.getRichStringCellValue();
        List<CTRElt> listElt = richText.getCTRst().getRList();

        // write cell info to sheet.xml
        String ref = new CellReferec(this._rownum, columnIndex).formatAsString();
        this._output.write("<c r=\"" + ref + "\"");
        CellStyle cellStyle = cell.getCellStyle();
        if(cellStyle.getIndex() != 0) {
            this._output.write(" s=\"" + cellStyle.getIndex() + "\"");
        }  

        this._output.write(" t=\"inlineStr\">");
        this._output.write("<is>");
        
        for(int i = 0; i < listElt.size(); i++) {
            CTRElt elt = listElt.get(i);
            if(elt.isSetRPr()) {
                // the case of having font styles
                this._output.write("<r>");
                this._output.write("<rPr>");
                // write rpr infomation, which CTRElt has (*)
                this._output.write("</rPr>");
                this._output.write("<t");
                if(hasLeadingTrailingSpaces(elt.getT())) {
                    this._output.write(" xml:space=\"preserve\"");
                }
                this._output.write(">");
                outputQuotedString(elt.getT());
                this._output.write("</t>");
                this._output.write("</r>");
            }
        }

        this._output.write("</is>");
        this._output.write("</c>");

    }
}


(Sorry, some parts(*) are ommitted.)
-----------------------------------------

Is there any problems in my code?
If possible, I hope it would be reflected in next version.

Thanks,
Comment 1 Dominik Stadler 2015-01-05 11:34:49 UTC
I tried to work on this, but there was support for SharedStringTables added via bug 53130, which is breaking your suggested implementation.

Any chance you can come up with an up-to-date patch here? Preferably in patch-format, see http://poi.apache.org/guidelines.html#SubmittingPatches for how this can be done.
Comment 2 PJ Fanning 2019-01-02 09:12:37 UTC
SharedStringsTable supports writing XML with reasonable support for the Open Office schema.