Bug 59098

Summary: XSSFRichTextString.append(string) applies font incorrectly
Product: POI Reporter: Mark Murphy <jmarkmurph>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 3.13-FINAL   
Target Milestone: ---   
Hardware: Other   
OS: other   

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
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 ***