Bug 48026 - Duplicate PageSettingsBlock record on XLS saved with Office 2003
Summary: Duplicate PageSettingsBlock record on XLS saved with Office 2003
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-FINAL
Hardware: PC Windows Vista
: P2 critical with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
: 48852 (view as bug list)
Depends on:
Reported: 2009-10-20 02:40 UTC by Tomas Prochazka
Modified: 2010-03-15 06:32 UTC (History)
1 user (show)

XLS saved in o2003 it work in old 3.5 beta 4 (82.50 KB, application/vnd.ms-excel)
2009-10-20 02:47 UTC, Tomas Prochazka
XLS saved in O2007 it work in 3.5 beta 5 and 3.5 final (73.00 KB, application/vnd.ms-excel)
2009-10-20 02:47 UTC, Tomas Prochazka
Excel 2000 Document (for test case) (179.50 KB, application/vnd.ms-excel)
2009-11-25 01:16 UTC, 20mithrandir

Note You need to log in before you can comment on or make changes to this bug.
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 );

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.

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