Hi Nick,

>>> 1/ read xlsx file with print settings
>>> 2/ call s.getPrintSetup() on a sheet (without doing anything else)
>>> 3/ save the xlsx file
>>> -> your print settings are going.
>>
...
>>
>> We can then use that as the basis for a test and fix. FWIW, I've just added 
>> a unit test that shows that:
>> * create new file
>> * add print settings
>> * save and re-open
>> * check print settings are as we set them
>> all works fine, so we really need a unit test for your case to spot what's 
>> up.
>>

My simple test case didn't trigger the problem either at first, but I
believe I found the root cause:

In XSSFWorksheet:

    public void setRepeatingRowsAndColumns(int sheetIndex,
                                           int startColumn, int endColumn,
                                           int startRow, int endRow) {
        ....

        XSSFPrintSetup printSetup = sheet.getPrintSetup();
        printSetup.setValidSettings(false);
    }

This sets the "valid settings" to false; when this happens, the
resulting xlsx gets:

<pageSetup scale="48" orientation="landscape"
horizontalDpi="4294967292" verticalDpi="4294967292"
usePrinterDefaults="false"/>

The usePrinterDefaults="false" then trigger Excel (at least the 2008
for Mac) to blatantly ignore the page settings even though they're
actually in the file. Not sure if that's a feature or a bug. Not sure
why "validSettings" gets written as "usePrinterDefaults". That in
itself seems suspect to me.

I ended up changing usePrinterDefaults to true, re-zipping it into an
xlsx file and voila. All fixed.

Code-wise, I inserted a

                        s1.getPrintSetup().setValidSettings(true);

after my setRepeatingRowsAndColumns() call and that seems to have
fixed the issue.

Anything more specific you need from my side ? Any comments on whether
this is a bug or not? I'm sure somebody put the
setValidSettings(false) there on purpose. Just not sure why nor why
that would get written as usePrinterDefaults.

Cheers,
- Filip

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to