You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/01/20 05:13:16 UTC

DO NOT REPLY [Bug 50623] New: Loss of data when writing large workbook to file

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: dev@poi.apache.org
        ReportedBy: elaine.wong.kl@gmail.com


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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 50623] Loss of data when writing large workbook to file

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50623

Elaine <el...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |elaine.wong.kl@gmail.com

-- 
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 50623] Loss of data when writing large workbook to file

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50623

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Nick Burch <ni...@alfresco.com> 2011-01-20 07:38:02 EST ---
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...

-- 
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org