https://issues.apache.org/bugzilla/show_bug.cgi?id=50623
Summary: Loss of data when writing large workbook to file
Product: POI
Version: 3.6
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: critical
Priority: P2
Component: HSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
I have created a new HSSFWorkbook and created new sheets, rows and cells. All
in all, I have 9 sheets, and the largest sheet has more than 10,000 rows. After
saving the workbook to a file, I opened the generated Excel file and noticed
that some cells are blank even though a value has been set.
I created a simple JUnit test to prove this(see below). What might be the cause
of this problem - and how should I overcome this?
Any advice would be much appreciated!
Elaine
---------------------- start of JUnit Test code
//1) Create 2 workbooks
String filePath = System.getProperty("user.dir") + File.seperator +
"myFile.xls";
Workbook wb1 = new HSSFWorkbook();
setWorkbook(wb1); //function to set a lot of data in wb1
FileOutputStream fileOut = new FileOutputStream(filePath , false);
wb1.write(fileOut);
fileOut.close();
Workbook wb2 = new HSSFWorkbook();
InputStream inp = new FileInputStream(filePath);
wb2 = new HSSFWorkbook(inp);
//2) Start comparing
assertTrue(wb1.getNumberOfSheets()==wb2.getNumberOfSheets());
for(int i=0; i<wb1.getNumberOfSheets(); i++){
String name = wb1.getSheetName(i);
Sheet sheet1 = wb1.getSheetAt(i);
Sheet sheet2 = wb2.getSheetAt(i);
assertTrue(sheet1.getLastRowNum()==sheet2.getLastRowNum());
for(int j=0; j<sheet1.getLastRowNum(); j++){
Row row1 = sheet1.getRow(j);
Row row2 = sheet2.getRow(j);
assertTrue(row1.getLastCellNum()==row2.getLastCellNum());
for(int k=0; k<row1.getLastCellNum(); k++){
if(row1.getCell(k)==null){
assertTrue(row2.getCell(k)==null);
continue;
}
if(row2.getCell(k)==null){
assertTrue(row1.getCell(k)==null);
//ASSERTION ERROR HAPPENS HERE!
continue;
}
assertTrue(row1.getCell(k).getCellType()==row2.getCell(k).getCellType());
if(row1.getCell(k).getCellType()==Cell.CELL_TYPE_NUMERIC ||
row1.getCell(k).getCellType()==Cell.CELL_TYPE_FORMULA){
assertTrue(row1.getCell(k).getNumericCellValue()==row2.getCell(k).getNumericCellValue());
if(row1.getCell(k).getCellType()==Cell.CELL_TYPE_STRING){
assertTrue(row1.getCell(k).getStringCellValue().trim().equals(row2.getCell(k).getStringCellValue().trim()));
}
}
}
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]