Okay, I've had a look at this one. Bad news I'm afraid. This big bug that's actually scattered all over the place. The basic problem is that we have a whole heap of bytes that are unsigned in excel. Unfortunately java bytes are signed.
The specific problem being triggered by this bug is that the HeaderRecord has a string field with a byte for the length. Once the string length becomes too large the byte becomes a negative number in Java and causes our problem. I can fix this problem up easily enough but there's plenty of other situations where the same thing can happen. I imagine this is going to be an issue for signed shorts also. There are two approaches to fixing this that I can see. 1. Check that client code handles the negative case. (Easy to miss something). 2. Store bytes and shorts, shorts as ints etc... (Wastes memory and maybe slower). Any further thoughts? Regards, Glen ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 27, 2002 12:16 AM Subject: [ poi-Bugs-522488 ] failed to create HSSFWorkbook > Bugs item #522488, was opened at 2002-02-25 07:54 > You can respond by visiting: > http://sourceforge.net/tracker/?func=detail&atid=406288&aid=522488&group_id= 32701 > > Category: HSSF API > Group: v 2.0 > Status: Open > Resolution: None > Priority: 5 > Submitted By: C. Mike Davis (c_mike_davis) > Assigned to: Glen Stampoultzis (gstamp) > Summary: failed to create HSSFWorkbook > > Initial Comment: > When I execute the following code on the attached > Excel file, I get a RecordFormatException at the > HSSFWorkbook constructor call in the line marked with > the comment "// *****". The attached file was > originally a larger file, but I stripped it down > sequentially to find the minimal example that still > throws the exception. > > > InputStream input = null; > BufferedInputStream buffInput = null; > POIFSFileSystem fs = null; > HSSFWorkbook workbook = null; > HSSFSheet sheet = null; > try { > URL sourceURL = new URL("file:/d:/data/bad excel > 29.xls"); > input = sourceURL.openStream(); > buffInput = new BufferedInputStream(input); > fs = new POIFSFileSystem(buffInput); > workbook = new HSSFWorkbook(fs); // ***** > sheet = workbook.getSheet("Sheet1"); > } catch (Throwable th) { > th.printStackTrace(); > } > > > > Message: > net.sourceforge.poi.hssf.record.RecordFormatException: > Unable to construct record instance > > net.sourceforge.poi.hssf.record.RecordFormatException: > Unable to construct record instance > > at > net.sourceforge.poi.hssf.record.RecordFactory.createRec > ord(RecordFactory.java:271) > > at > net.sourceforge.poi.hssf.record.RecordFactory.createRec > ords(RecordFactory.java:202) > > at > net.sourceforge.poi.hssf.usermodel.HSSFWorkbook.<init> > (HSSFWorkbook.java:156) > > .... > > ---------------------------------------------------------------------- > > >Comment By: Andrew C. Oliver (acoliver2) > Date: 2002-02-26 05:16 > > Message: > Logged In: YES > user_id=287767 > > Give me a couple days. I'll take a look. Make sure that > your workbook is not protected and that it is an Excel 97 or > better workbook. (note StarOffice 5.1 actuall generated > more Excel 95ish workbooks) > > > > ---------------------------------------------------------------------- > > You can respond by visiting: > http://sourceforge.net/tracker/?func=detail&atid=406288&aid=522488&group_id= 32701 >
