Bug 48026

Summary: Duplicate PageSettingsBlock record on XLS saved with Office 2003
Product: POI Reporter: Tomas Prochazka <t.prochazka>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: critical CC: bzane
Priority: P2    
Version: 3.5-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Attachments: XLS saved in o2003 it work in old 3.5 beta 4
XLS saved in O2007 it work in 3.5 beta 5 and 3.5 final
Excel 2000 Document (for test case)

Description Tomas Prochazka 2009-10-20 02:40:13 UTC
Version 3.5-beta4 had problem with reading XLS saved in Office 2007, this was fixed in 3.5-beta5, but now not working document saved in old Office 2003. It's possible fix it for booth version?

Here is Exception:

Exception in thread "main" org.apache.poi.hssf.record.RecordFormatException: Duplicate PageSettingsBlock record (sid=0x89c)
        at org.apache.poi.hssf.record.aggregates.PageSettingsBlock.checkNotPresent(PageSettingsBlock.java:227)
        at org.apache.poi.hssf.record.aggregates.PageSettingsBlock.readARecord(PageSettingsBlock.java:215)
        at org.apache.poi.hssf.record.aggregates.PageSettingsBlock.addLateRecords(PageSettingsBlock.java:639)
        at org.apache.poi.hssf.model.Sheet.<init>(Sheet.java:222)
        at org.apache.poi.hssf.model.Sheet.createSheet(Sheet.java:158)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:286)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:200)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:316)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:297)
        at cz.atomsoft.actum.carrefour.carrefourhelper.tasks.XlsToAccessConverter.convert(XlsToAccessConverter.java:90)
        at cz.atomsoft.actum.carrefour.carrefourhelper.tasks.XlsToAccessConverter.convert(XlsToAccessConverter.java:78)
        at cz.atomsoft.actum.carrefour.carrefourhelper.tasks.XlsToAccessConverter.searchFolderAndConverAllFiles(XlsToAccessConverter.java:73)
        at cz.atomsoft.actum.carrefour.carrefourhelper.tasks.XlsToAccessConverter.process(XlsToAccessConverter.java:59)
        at cz.atomsoft.actum.carrefour.carrefourhelper.App.main(App.java:23)
Comment 1 Tomas Prochazka 2009-10-20 02:47:08 UTC
Created attachment 24399 [details]
XLS saved in o2003 it work in old 3.5 beta 4
Comment 2 Tomas Prochazka 2009-10-20 02:47:55 UTC
Created attachment 24400 [details]
XLS saved in O2007 it work in 3.5 beta 5 and 3.5 final
Comment 3 20mithrandir 2009-11-25 01:16:42 UTC
Created attachment 24608 [details]
Excel 2000 Document (for test case)

I added an Excel 2000 file for testing purposes. I am getting the mentioned RecordFormatException in 3.5-FINAL but 3.5-beta4 works fine.

Here's my test code:
static void copyPoi( File xlsFile ) throws Exception
{
    File tgt = new File( xlsFile.getParentFile(), xlsFile.getName() + ".P.xls" );
    
    HSSFWorkbook wbook = new HSSFWorkbook( new FileInputStream( xlsFile ) );
    
    FileOutputStream out = new FileOutputStream( tgt );
    wbook.write( out );
    out.close();
}

I'd really appreciate a fix for this issue very soon. Maybe if someone could give me direction I'd be able to look in the concerning source-code myself...
Comment 4 Yegor Kozlov 2009-12-19 03:53:38 UTC
Fixed in r892468

It took time to understand the meaning of the duplicate records and how Excel 2007 repositions them when saving such a file. The fix mimics Excel 2007: duplicates in PageSettingsBlock are not ignored. In the observed cases they are related to custom sheet views and Excel 2007 moves them to the appropriate block. So does POI.

Yegor
Comment 5 Yegor Kozlov 2010-03-15 06:32:17 UTC
*** Bug 48852 has been marked as a duplicate of this bug. ***