Bug 51321 - XSSFCell.setCellValue should not strip off ending spaces
Summary: XSSFCell.setCellValue should not strip off ending spaces
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: All All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-03 19:49 UTC by jxz164
Modified: 2011-06-07 20:58 UTC (History)
0 users



Attachments
java code to reproduce the setCellValue bug in XSSFCell.java (877 bytes, application/octet-stream)
2011-06-03 19:49 UTC, jxz164
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jxz164 2011-06-03 19:49:04 UTC
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();
    }
}
Comment 1 jxz164 2011-06-03 19:50:57 UTC
Both cells are populated with "ABC " to be more clear.
Comment 2 Nick Burch 2011-06-03 19:54:02 UTC
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?
Comment 3 jxz164 2011-06-07 14:29:41 UTC
OK. I have confirmed that this is fixed in the newly released poi-3.8-beta3.

Thanks!