Bug 50623 - Loss of data when writing large workbook to file
Summary: Loss of data when writing large workbook to file
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.6-FINAL
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-19 23:13 UTC by Elaine
Modified: 2015-05-31 21:46 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elaine 2011-01-19 23:13:12 UTC
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()));
            }
        }
    }
}
Comment 1 Nick Burch 2011-01-20 07:38:02 UTC
Are you able to create a self-contained unit test for this? One that populates two sheets with the same data, and then verifies the contents + shows something's missing?

As it stands, there's not enough to show the problem's in POI rather than in your own code that populates the workbook...
Comment 2 Dominik Stadler 2015-05-31 21:46:09 UTC
No update for a long time, thus resolving this as WORKSFORME for now. If this is still a problem then please reopen this bug with more information via a self-sufficient unit-test that allows us to reproduce the problem.