Bug 57294 - RichText is converted to nomal text in SXSSF
Summary: RichText is converted to nomal text in SXSSF
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on: 52972
Blocks:
  Show dependency tree
 
Reported: 2014-12-02 10:45 UTC by Conny Yuka
Modified: 2019-01-02 09:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.