Hi, the Exception indicates that POI expects the binary records in the XLS-format to have some more data, but it is not available any more. Sometimes Excel and LibreOffice are a bit less strict on such formattings. There are some options:
* You could find out how the documents are created and try to get them created in a more specification-conforming way * You can use the application BiffViewer from the POI source to see which records are not read correctly * You can try if it works if you change POI source-code to catch the exception at the third short in InfoSubRecord() and only report a warning as the error happens at a point where two empty bytes are read anyway. Dominik. On Fri, Feb 12, 2016 at 2:30 PM, Jatin Puri <[email protected]> wrote: > Hello. > > We are currently using poi 3.13. We get over a 1000 excels a day which we > parse using poi. But since last few days, for a new set of `.xls` files, it > fails with the below exception: > > Exception in thread "main" > org.apache.poi.hssf.record.RecordFormatException: Not enough data (1) to > read requested (2) bytes > at > > org.apache.poi.hssf.record.RecordInputStream.checkRecordPosition(RecordInputStream.java:226) > at > > org.apache.poi.hssf.record.RecordInputStream.readShort(RecordInputStream.java:243) > at > > org.apache.poi.hssf.record.ExtSSTRecord$InfoSubRecord.<init>(ExtSSTRecord.java:62) > at org.apache.poi.hssf.record.ExtSSTRecord.<init>(ExtSSTRecord.java:97) > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) > at > > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) > at > > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) > at java.lang.reflect.Constructor.newInstance(Constructor.java:422) > at > > org.apache.poi.hssf.record.RecordFactory$ReflectionConstructorRecordCreator.create(RecordFactory.java:84) > at > > org.apache.poi.hssf.record.RecordFactory.createSingleRecord(RecordFactory.java:334) > at > > org.apache.poi.hssf.record.RecordFactoryInputStream.readNextRecord(RecordFactoryInputStream.java:308) > at > > org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:274) > at > > org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:478) > at > org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:344) > at > org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:401) > > > *Important Note*: > > 1. If I open the `.xls` file with Microsoft Excel 2010. And simply save > it. i.e. make no change but just save it and then run the saved file. > *It > succeeds.* > 2. I am not sure if it is useful, but sharing it this case: While > debugging, I have realized, that the error comes towards reading > records at > end of the file. i.e. it has read all the visible contents and only > towards > almost end of file, it fails. > > Sadly, I cannot share the excel as it is confidential. Removing contents > and sharing wont help as on saving, it works perfectly fine. Any help? > > Thanks! > Jatin > > > -- > Jatin Puri > http://jatinpuri.com <http://www.jatinpuri.com> >
