Bug 54969

Summary: [PATCH] XSSFTextBox doesn't behave properly
Product: POI Reporter: Sean Newell <sanewell92>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal CC: robertsdjguard-poidev
Priority: P2 Keywords: PatchAvailable
Version: 3.9-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Class demonstrating the bug
Patch which fixes the font issue and implements unit test verifying that the font and color attributes are passed through correctly

Description Sean Newell 2013-05-14 15:36:44 UTC
Created attachment 30284 [details]
Class demonstrating the bug

See semi-solved Stack Overflow question : 

http://stackoverflow.com/questions/16529787/how-to-change-font-on-xssftextbox


So two things, one has a fairly easy work-around and the other is just annoying: Firstly (easy work-around but limiting) I have to retrieve the underlying CTTextCharacterProperties object to actually change the font, which is strange in the first place; as the other guy on SO said, it seems like the XSSFSimpleShape.applyAttributes method doesn't deal with Fonts correctly, but rather only Font Families, which is not what is expected when applying a Font to a RichTextField to use it as the text for an XSSFTextBox; I expect that applied Font to be correctly and fully applied, not to mention that the only colors that seem to be applied are Font.COLOR_NORMAL and Font.COLR_RED enums. Unless this is what you want us to use, which documentation never says to; I would normally simply create a new XSSFColor(java.awt.Color.BLACK) like I do with fonts and styles for cells, but that does not work here (I always would get white color default font when I try and do it intuitively).

Second, with Excel 2010 when I call setFillColor on an XSSFTextBox object upon opening the spreadsheet Excel tells me that it found unreadable content and then it repairs xml, specifically
"Repaired Records: Drawing from /xl/drawings/drawing1.xml part (Drawing shape)"

If I comment out setFillColor I don't get this bit. I've also tried using the underlying CTTextCharacterProperties Object to fill the TextBox, making a reference Object rpr from a XSSFTextBox instance call getCTShape().getTxBody().getPArray(0).getRArray(0).getRPr(), I then do this :
Color col = Color.PINK; and invoke
rpr.addNewSolidFill().addNewSrgbClr().setVal(); and pass in a new byte array from values from col. This does not fill the XSSFTextBox, and it makes excel find unreadable content as well, so at the moment I use setFillColor, but I can't have excel finding unreadable content as the users who will be using my program won't know what is happening and think something went wrong.


Thanks for taking the time to read this! I'm not sure if this is an Excel 2010 specific thing, or if I'm calling/dealing with XSSFTextBox incorrectly, or what; attaching source code.
Comment 1 Darren Roberts 2013-07-19 14:30:40 UTC
Created attachment 30603 [details]
Patch which fixes the font issue and implements unit test verifying that the font and color attributes are passed through correctly

I've attached a patch which fixes the font issue and implements unit test verifying that the font and color attributes are passed through correctly.

I suspect your other problem is related to shape groups - do you see the same issue if you create the textboxes as indivdual entities?
Comment 2 Dominik Stadler 2015-09-07 20:09:26 UTC
This seems to have been applied since a long time already via bug 55292

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