Created attachment 27106 [details] java code to reproduce the setCellValue bug in XSSFCell.java I am creating a xlsx file with only two cells. One cell is created with value "ABC " and the other cell is created with value "ABC ". Please note that the second cell differs from the first cell only with more ending spaces. However, in the generated xlsx file, both cells are populated with value "ABC ". I believe the setCellValue method in XSSFCell.java has a bug. Perhaps it was using a pre-evaluated result string incorrectly in this case. Please see the attached code to reproduce this problem. package org.apache.poi.ss.examples; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; import java.io.FileOutputStream; public class XSSFSetValueBug { public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("sheet1"); CreationHelper createHelper = wb.getCreationHelper(); Cell cell0 = sheet.createRow(0).createCell(0); cell0.setCellValue(createHelper.createRichTextString("ABC ")); Cell cell1 = sheet.createRow(1).createCell(0); cell1.setCellValue(createHelper.createRichTextString("ABC ")); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("C:\\workspace\\TestXSSFSetValueBug.xlsx"); wb.write(fileOut); fileOut.close(); } }
Both cells are populated with "ABC " to be more clear.
There's code in XSSFRichTextString (which XSSFCell uses) to handle leading and trailing spaces, which ought to be kicking in to solve this issue Can you try with a recent nightly build / svn checkout and see if you still have the problem?
OK. I have confirmed that this is fixed in the newly released poi-3.8-beta3. Thanks!