Bug 15375 - Post 1.5.1 POI causes spreadsheet to become unopenable.
Summary: Post 1.5.1 POI causes spreadsheet to become unopenable.
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-dev
Hardware: Other other
: P3 blocker with 13 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 21305 21646 22568 23445 23628 24355 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-12-14 22:03 UTC by Greg Garson
Modified: 2004-11-16 19:05 UTC (History)
6 users (show)



Attachments
The file being modified that fails. The code is attempting to modify the first sheet of this workbook. (28.50 KB, application/octet-stream)
2002-12-14 22:05 UTC, Greg Garson
Details
Here is the barebones version of the failing code. With further testing i've found this code does work with POI 1.6 Dev but fails with all subsequent versions. (7.39 KB, text/plain)
2002-12-16 00:00 UTC, Greg Garson
Details
original xls file (27.50 KB, application/octet-stream)
2003-01-15 16:53 UTC, Chris Haddad
Details
file corrupted by poi (49.00 KB, application/octet-stream)
2003-01-15 16:54 UTC, Chris Haddad
Details
sample code with main() demonstrating the excel error when loading the file. Excel 2000 9.0.4402 sr1 on w2k used. (1.30 KB, text/plain)
2003-01-15 17:45 UTC, Chris Haddad
Details
A small class that can simulate this error (2.06 KB, patch)
2003-07-18 09:19 UTC, Jeff
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Garson 2002-12-14 22:03:05 UTC
When modifying an Excel 2000 Spreadsheet to add extra rows and columns the code 
completes as expected but causes either an 'Unable to open file' message from 
Excel or for the spreadsheet to briefly flash on screen and then disappear.

The code that causes this problem is:

String[][] accountCodes = dataHandler.getAcctCodeList(data.getCostCenter());
        HSSFCell cell = null;
        HSSFCellStyle cellStyle = null;
        HSSFRow row = sheet.getRow(rowPos);
        String[] accountCode = null;
        int a = 0;
        row = sheet.createRow((short)(rowPos));
        cell = row.createCell((short)cellPos);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellStyle(headerStyle);
        cell.setCellValue("Account Code (and description)");
        a++;
        for(;(accountCodes != null) && (a<=accountCodes.length-1);a++){
            accountCode = accountCodes[a];
            //Fails when adding this row
            row = sheet.createRow((short)(rowPos+a));
            cell = row.createCell((short)cellPos);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellStyle(bodyStyle);
            cell.setCellValue(accountCode[0] + " - " + accountCode[1]);
        }
        return a;

This is not a problem in 1.5.1
Comment 1 Greg Garson 2002-12-14 22:05:10 UTC
Created attachment 4168 [details]
The file being modified that fails.  The code is attempting to modify the first sheet of this workbook.
Comment 2 Andy Oliver 2002-12-15 04:05:16 UTC
Give another code sample which is just a simple "main" class and is the least
amount of code required to replicate the problem.  I'm pretty suspicious of this
bug.
Comment 3 Greg Garson 2002-12-16 00:00:51 UTC
Created attachment 4173 [details]
Here is the barebones version of the failing code.  With further testing i've found this code does work with POI 1.6 Dev but fails with all subsequent versions.
Comment 4 Chris Haddad 2003-01-14 16:47:39 UTC
This is failing for me as well using the 1.8.0 distribution.  I'm surprised, 
because my test case is *very* basic (using Excell 2000) and taken right from 
the docs.

    HSSFWorkbook wb = new HSSFWorkbook(fs);
    HSSFSheet sheet = wb.getSheetAt(0);
    
    HSSFRow row = sheet.getRow(5);
    HSSFCell cell = row.getCell((short)3);
    if (cell == null)
        cell = row.createCell((short)3);
        
        // Write test
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue("a test");

Comment 5 Chris Haddad 2003-01-15 16:53:30 UTC
Created attachment 4429 [details]
original xls file
Comment 6 Chris Haddad 2003-01-15 16:54:05 UTC
Created attachment 4430 [details]
file corrupted by poi
Comment 7 Chris Haddad 2003-01-15 16:57:48 UTC
Here is the code that corrupts the xls file (1/15/03 16:53 attachment to this 
bug report) when using the 1.9.0 nightly build from 20030115:

    public void poiXlsTest() {      
      
      try {
    POIFSFileSystem fs      =
            new POIFSFileSystem(new FileInputStream
("/usr/local/data/dashView.xls"));
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    HSSFSheet sheet = wb.getSheetAt(0);
    
    HSSFRow row = sheet.getRow(5);
    HSSFCell cell = row.getCell((short)3);
    if (cell == null)
        cell = row.createCell((short)3);
        
        // Write test
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue("a test");

        // change existing numeric cell value
    log.debug("change existing numeric cell");
    HSSFRow oRow = sheet.getRow(14);
    HSSFCell oCell = oRow.getCell((short)4);
    oCell.setCellValue(75);
    oCell = oRow.getCell((short)5);
    oCell.setCellValue("0.3");
    
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("/usr/local/data/dashView-
1.xls");
    wb.write(fileOut);
    fileOut.close();
  }
  catch (java.io.FileNotFoundException ex)
  {
    log.error(ex.getMessage());
  }
  catch (java.io.IOException ex)
  {
    log.error(ex.getMessage());
  }
  
  }
Comment 8 Andy Oliver 2003-01-15 17:10:42 UTC
Resubmit the ExcelTest in a simpler form.  As it stands I'd have to spend too
much time tracing through your sample.  It appears this may indeed be a bug, but
I can't rule out a bug in the sample.  When we say "the simplest possible
example" we envision a monolitic class with main() which does things clearly in
a linear fashion...   There is a little too much for me to grok in a limited
amount of time.  
Comment 9 Andy Oliver 2003-01-15 17:23:25 UTC
new sample submitted by haddad should be adequate.  I'll take a look.
Comment 10 Chris Haddad 2003-01-15 17:45:41 UTC
Created attachment 4435 [details]
sample code with main() demonstrating the excel error when loading the file.  Excel 2000 9.0.4402 sr1 on w2k used.
Comment 11 Tim Schafer 2003-06-19 19:19:08 UTC
I have tried:
jakarta-poi-1.8.0-dev-20020919.jar
jakarta-poi-1.10.0-dev-20030222.jar
poi-2.0-pre1-20030517.jar

In each case using POI to modify (per example provided by Chris Haddad)
a blank (open Excel press save) spreadsheet created using each of:
Excel 2000 (9.0.2720)
Excel 2002 (10.2614.2625)
resulted in a blank spreadsheet

Using other input spreadsheets of varying complexity would result in a corrupt
output spreadsheet
But generally the result spreadsheet appeared as if it had not been modified

This problem does not occur using jakarta-poi-1.5.1-final-20020615.jar
Comment 12 Jeff 2003-07-18 09:19:07 UTC
Created attachment 7367 [details]
A small class that can simulate this error
Comment 13 Jeff 2003-07-18 09:23:08 UTC
I have a similar problem and have managed to simulate it with a small class.
I think it has to do with string references?(See class)
Comment 14 Andy Oliver 2003-07-18 12:50:54 UTC
Have you tried this with 2.0-pre2?  1.5.x will not get new fixes this close to a release.
Comment 15 Jeff 2003-07-21 06:06:44 UTC
This fault only happens with 2.0-pre2. 

It does not happen with jakarta-poi-1.5.1-final

Comment 16 Jeff 2003-07-24 11:15:05 UTC
I have noticed that (In my case) as soon as the SST table becomes very big this 
happens.

I can put thousands of strings into a spreadsheet as long as there are not too 
many unique ones. As soon as there are plenty unique strings the sheet can't 
open.

Using the BIFF Viewer, I see that CONTINUE RECORD's are written for the 
spreadsheet that can't open and none are written for a spreadsheet that can 
open.

From looking at the source (I am not sure though) it seems that these CONTINUE 
RECORDs are a major change between POI 1.5.1 and POI2.

Am I on the wrong track ???
Comment 17 Avik Sengupta 2003-10-06 09:40:11 UTC
*** Bug 23445 has been marked as a duplicate of this bug. ***
Comment 18 Avik Sengupta 2003-10-06 09:46:57 UTC
*** Bug 22568 has been marked as a duplicate of this bug. ***
Comment 19 Avik Sengupta 2003-10-06 10:39:25 UTC
OK, This bug is now fixed thanks to Jason's SST/Continue record fixes. I would
appreciate if some of the original reporters would try out a latest nightly or
CVS build, and report if they can confirm the fix. We should do a release once
we get some more confirmation.   
Comment 20 Jason Height 2003-10-06 22:09:23 UTC
*** Bug 23628 has been marked as a duplicate of this bug. ***
Comment 21 Avik Sengupta 2003-10-07 15:58:06 UTC
*** Bug 21646 has been marked as a duplicate of this bug. ***
Comment 22 Robert Lowe 2003-10-08 15:10:08 UTC
I tried a build from CVS and can confirm that it fixes the problem I was 
having. Fantastic!

A speedy release would be *very* much appreciated!
Comment 23 Avik Sengupta 2003-10-08 18:11:10 UTC
Cool. Big round of applause for Jason!

Closing this bug. Please reopen with testcase if you still have a problem.
Before you do, please check test15375, test15375_2, and test22568 in
TestBugs.java, which are the proof that this bug is fixed. 
Comment 24 Rudi Strydom 2003-10-13 08:35:09 UTC
Big round of applause for Jeff who actually found the problem with the continue 
records! Nice going boet.
Comment 25 Avik Sengupta 2003-10-30 19:01:03 UTC
*** Bug 21305 has been marked as a duplicate of this bug. ***
Comment 26 Avik Sengupta 2003-11-03 17:54:22 UTC
*** Bug 24355 has been marked as a duplicate of this bug. ***