Bug 49253

Summary: setRepeatingRowsAndColumns sets print orientation from landscape to portrait
Product: POI Reporter: Thomas Herre <thomas.herre>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.6-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Workbook with wrong orientation
Workbook with correct orientation

Description Thomas Herre 2010-05-05 10:19:53 UTC
I have an XSSFWorkbook in which I set the page/print orientation to landscape and set one row/some columns to repeat on each page. After setting the repeating rows and columns, Excel displays orientation portrait instead of the desired landscape.

Test code:

        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("1");
        cell = row.createCell(1);
        cell.setCellValue("2");
        cell = row.createCell(2);
        
        PrintSetup printSetup = sheet.getPrintSetup();
        printSetup.setLandscape(true);
        
        workbook.setRepeatingRowsAndColumns(0, 0, 1, 0, 0);
        // printSetup.setValidSettings(true);
        
        workbook.write(new FileOutputStream(new File("test-landscape.xlsx")));

Now open the file in Excel and check the page settings. 
It displays "portrait". That's wrong!

Now, if you comment in the line: 
printSetup.setValidSettings(true);
and run the test again, the resulting file shows "landscape" again. Correct.

Looking into the sources, I found that in the last statement of method setRepeatingRowsAndColumns, printSetup.setValidSettings(false); is called,
which led me to the described workaround.
Comment 1 Thomas Herre 2010-05-05 10:22:42 UTC
Created attachment 25401 [details]
Workbook with wrong orientation
Comment 2 Thomas Herre 2010-05-05 10:23:47 UTC
Created attachment 25402 [details]
Workbook with correct orientation

This workbook was created using the workaround as described in the bug report.
Comment 3 Nick Burch 2011-03-18 12:06:37 UTC
Filip Defoort reported much the same thing on the mailing list last week. Based on his postings, and this bug report, I think I've fixed this in r1082961 (along with a unit test).
Comment 4 filipdef 2011-03-30 18:57:47 UTC
Thanks for fixing this one - I was just gettin' around to actually filing a bug for it !

- Filip