Summary: | setLandscape(true) has no effect on a loaded sheet. | ||
---|---|---|---|
Product: | POI | Reporter: | Andreas Kramer <andreas.kramer> |
Component: | HSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED WONTFIX | ||
Severity: | normal | CC: | vinu.kumar |
Priority: | P2 | ||
Version: | 3.0-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Attachments: |
the template file
The workbook i created with the given reproduce code |
Description
Andreas Kramer
2007-10-24 09:25:14 UTC
Created attachment 21037 [details]
the template file
Created attachment 21038 [details]
The workbook i created with the given reproduce code
I've added two new tests to src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java One of these does setLandscape on an existing sheet, the other on a newly created sheet. (Methods are testPrintSetupLandscapeNew() and testPrintSetupLandscapeExisting()) After doing a save and a re-open, getLandscape is correctly working for both of them. Could you please create a failing testcase for your problem, and attach that to the bug? As it is, I'm unable to replicate your problem. I am able to reproduce this behaviour. The methods work fine in xlsx file while they dont work in xls file. The client in MS Excel 2007. PrintSetup setup = s.getPrintSetup(); setup.setPaperSize(PrintSetup.LEGAL_PAPERSIZE); setup.setLandscape(true); Print properties for an xlsx file show the paper size as LEGAL and it is also set to landscape mode, whereas in xls file the paper size is A4 (default) and its set to portrait. Note: The get methods show the correct values I am using POI 3.5 final The following code can be used to reproduce this problem. Create a standard blank workbook and save it as test.xls. Compile and run the following TestPOI.java source. Open the out.xls file in excel and choose 'File' -> 'Page Setup' from the application menu. The page orientation has not changed to Landscape. import java.io.*; import org.apache.poi.hssf.usermodel.*; import java.util.*; public class TestPOI { public static void main(String[] args) throws Exception{ HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("test.xls")); int sheetCount = workbook.getNumberOfSheets(); for (int i = 0; i < sheetCount; i++){ System.out.println(i); HSSFSheet sheet = workbook.getSheetAt(i); HSSFPrintSetup print = sheet.getPrintSetup(); print.setLandscape(true); } workbook.write(new FileOutputStream("out.xls")); } } (In reply to comment #6) This problem still occurs in poi-3.6-20091214 It seems Excel has some strange checking on the values set in the PrintSetup, so if you do not set all of them to useful values, Excel may ignore the settings and use defaults, e.g. what did work for me was the following: setup.setLandscape(true); setup.setPaperSize(PrintSetup.A4_PAPERSIZE); setup.setScale((short)100); setup.setValidSettings(false); Also the setValidSettings() could be interferring here. Generally it should be "false" to not make Excel use default values! However I don't think we can re-implement the checking that Excel does internally as it is not part of the Spec and thus a complete mystery to us, so I think this is WONTFIX for us unless someone comes up with a better way to handle the print settings. |