Bug 48070 - Preserving leading and trailing spaces XSSFCell
Summary: Preserving leading and trailing spaces XSSFCell
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-FINAL
Hardware: All Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-10-27 12:51 UTC by Dale Monti
Modified: 2009-10-28 03:44 UTC (History)
0 users


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

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.