Bug 48070

Summary: Preserving leading and trailing spaces XSSFCell
Product: POI Reporter: Dale Monti <dmonti>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.5-FINAL   
Target Milestone: ---   
Hardware: All   
OS: Windows Vista   

Description Dale Monti 2009-10-27 12:51:22 UTC
I would like to have a string value in a cell that maintains the leading and trailing spaces. If I set a String value in a cell with leading and trailing spaces, the value seems to be preserved in the XML, but does not display in Excel.
For example:
XSSFCell cell = row.createCell(0);
cell.setCellValue("   XYZ   ");

Yields <si><t>   XYZ   </t></si> in sharedStrings.xml but does not display the spaces in Excel.

If you just type the value in Excel you get
<si><t xml:space="preserve">    XYZ    </t></si> 

POI should have some way of preserving these spaces.

Thanks
Comment 1 Yegor Kozlov 2009-10-28 03:44:12 UTC
Fixed in r830492

The fix looks easy on the surface but it took quite a while to understand how to do it with XmlBeans. xml:space="preserve" belongs to the Official XML Namespace  (http://www.w3.org/XML/1998/namespace) and XmlBeans does not generate get/set accessors to it. It turned out that the only way to set this attribute is via XmlCursor, see the patch.

Yegor