Bug 59098 - XSSFRichTextString.append(string) applies font incorrectly
Summary: XSSFRichTextString.append(string) applies font incorrectly
Status: RESOLVED DUPLICATE of bug 58315
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.13-FINAL
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2016-03-02 13:20 UTC by Mark Murphy
Modified: 2016-03-11 22:24 UTC (History)
0 users


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

    <t xml:space="preserve">This is correct </t>
      <sz val="11"/>
      <color indexed="10"/>
      <rFont val="Calibri"/>
      <family val="2"/>
    <t>This is Bold Red</t>
      <sz val="11"/>
      <color indexed="8"/>
      <rFont val="Calibri"/>
      <family val="2"/>
      <scheme val="minor"/>
    <t xml:space="preserve"> This uses the default font rather than the cell style font</t>

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
I could not reproduce this with a small unit-test. There was a related fix in POI 3.14 via bug 58315, so please try again with release 3.14 and reopen this bug, ideally with a standalone junit-test which reproduces the problem.

*** This bug has been marked as a duplicate of bug 58315 ***