|Summary:||XSSFRichTextString.append(string) applies font incorrectly|
|Product:||POI||Reporter:||Mark Murphy <jmarkmurph>|
|Component:||XSSF||Assignee:||POI Developers List <dev>|
Description Mark Murphy 2016-03-02 13:20:03 UTC
XSSFRichTextString.append(string) works correctly if the value of the XSSFRichTextString is empty. However if a different font has been applied to a section of the text, it applies a font, I believe the default font, which is wrong (different from the way Excel works). append(string) should append a string without a font which will allow the text to use the cell style to determine the font. See the following example XML generated by XSSFRichTextString rts = new XSSFRichTextString(); rts.append("This is correct "); rts.append("This is Bold Red", BoldRed); rts.append(" This uses the default font rather than the cell style font"); <si> <r> <t xml:space="preserve">This is correct </t> </r> <r> <rPr> <b/> <sz val="11"/> <color indexed="10"/> <rFont val="Calibri"/> <family val="2"/> </rPr> <t>This is Bold Red</t> </r> <r> <rPr> <sz val="11"/> <color indexed="8"/> <rFont val="Calibri"/> <family val="2"/> <scheme val="minor"/> </rPr> <t xml:space="preserve"> This uses the default font rather than the cell style font</t> </r> </si> You can clearly see the three text groupings added by the three append methods. The first does not include a font, and consequently does not include an <rPr> node. The second does include a font, and does include an <rPr> node. However, the third append does not include a font, and thus should not include an <rPr> node. In Excel If I take this string, and bold red the date string in the middle of it, the two other strings have no <rPr> nodes, which is what I expected. The result is that if the cell style uses other than the default font, only the first append(string) method will add text that uses the font in the cell style. Any append(string) methods called after an append(string, font) call will explicitly use the spreadsheet default font.
Comment 1 Mark Murphy 2016-03-02 13:23:58 UTC
Whoops, I change the data to protect the innocent, but did not change my description. The date string above was changed to "This is Bold Red". Also, I found this XML in the sharedStrings.xml in the final spreadsheet.
Comment 2 Dominik Stadler 2016-03-11 22:24:47 UTC