From 39955f60f82fbed3eaf87f219a8f2ecf00e9f33a Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Wed, 17 Jun 2015 14:26:31 +0000 Subject: [PATCH] Make setLandscape(false) and setLeftToRight(false) do what one would expect git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1686019 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFPrintSetup.java | 4 ++ .../xssf/usermodel/TestXSSFPrintSetup.java | 46 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java index ecbbe8ecd6..43b8c5a212 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java @@ -120,6 +120,8 @@ public class XSSFPrintSetup implements PrintSetup { public void setLeftToRight(boolean ltor) { if (ltor) setPageOrder(PageOrder.OVER_THEN_DOWN); + else + setPageOrder(PageOrder.DOWN_THEN_OVER); } /** @@ -130,6 +132,8 @@ public class XSSFPrintSetup implements PrintSetup { public void setLandscape(boolean ls) { if (ls) setOrientation(PrintOrientation.LANDSCAPE); + else + setOrientation(PrintOrientation.PORTRAIT); } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java index 3001197cd4..6cda3aff29 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java @@ -19,12 +19,18 @@ package org.apache.poi.xssf.usermodel; import junit.framework.TestCase; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; -import org.apache.poi.ss.usermodel.PaperSize; import org.apache.poi.ss.usermodel.PageOrder; -import org.apache.poi.ss.usermodel.PrintOrientation; +import org.apache.poi.ss.usermodel.PaperSize; import org.apache.poi.ss.usermodel.PrintCellComments; +import org.apache.poi.ss.usermodel.PrintOrientation; import org.apache.poi.xssf.XSSFITestDataProvider; +import org.junit.Test; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder; /** * Tests for {@link XSSFPrintSetup} @@ -226,10 +232,10 @@ public class TestXSSFPrintSetup extends TestCase { assertEquals(true, s2.getCTWorksheet().isSetPageMargins()); // Round trip and check - wb = XSSFITestDataProvider.instance.writeOutAndReadBack(wb); + XSSFWorkbook wbBack = XSSFITestDataProvider.instance.writeOutAndReadBack(wb); - s1 = wb.getSheetAt(0); - s2 = wb.getSheetAt(1); + s1 = wbBack.getSheetAt(0); + s2 = wbBack.getSheetAt(1); assertEquals(true, s1.getCTWorksheet().isSetPageSetup()); assertEquals(true, s1.getCTWorksheet().isSetPageMargins()); @@ -239,6 +245,8 @@ public class TestXSSFPrintSetup extends TestCase { print = s1.getPrintSetup(); assertEquals(3, print.getCopies()); assertEquals(true, print.getLandscape()); + + wb.close(); } /** @@ -248,4 +256,30 @@ public class TestXSSFPrintSetup extends TestCase { public void testRoundTrip() { // TODO } + + @Test + public void testSetLandscapeFalse() throws Exception { + XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance()); + + assertFalse(ps.getLandscape()); + + ps.setLandscape(true); + assertTrue(ps.getLandscape()); + + ps.setLandscape(false); + assertFalse(ps.getLandscape()); + } + + @Test + public void testSetLeftToRight() throws Exception { + XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance()); + + assertFalse(ps.getLeftToRight()); + + ps.setLeftToRight(true); + assertTrue(ps.getLeftToRight()); + + ps.setLeftToRight(false); + assertFalse(ps.getLeftToRight()); + } } -- 2.39.5