]> source.dussan.org Git - poi.git/commitdiff
Tweak XSSFPrintSetup to make it a little clearer what happens, and add a round-trip...
authorNick Burch <nick@apache.org>
Tue, 1 Mar 2011 21:02:43 +0000 (21:02 +0000)
committerNick Burch <nick@apache.org>
Tue, 1 Mar 2011 21:02:43 +0000 (21:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1076022 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java

index 2078038c9d8541d29b77c6c97f5deabb6031fa9f..ecbbe8ecd6d5e31371359a23a94291afbb0750f8 100644 (file)
@@ -35,16 +35,23 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
  * Page setup and page margins settings for the worksheet.
  */
 public class XSSFPrintSetup implements PrintSetup {
-
     private CTWorksheet ctWorksheet;
     private CTPageSetup pageSetup;
     private CTPageMargins pageMargins;
 
-
     protected XSSFPrintSetup(CTWorksheet worksheet) {
         this.ctWorksheet = worksheet;
-        this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
-        this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
+        
+        if(ctWorksheet.isSetPageSetup()) {
+           this.pageSetup = ctWorksheet.getPageSetup();
+        } else {
+           this.pageSetup = ctWorksheet.addNewPageSetup();
+        }
+        if(ctWorksheet.isSetPageMargins()) {
+           this.pageMargins = ctWorksheet.getPageMargins();
+        } else {
+           this.pageMargins = ctWorksheet.addNewPageMargins();
+        }
     }
 
     /**
index c3cee3953b75ba55369bb1171dcdb7eeb42a7fa9..3001197cd436ccf7edb7fcfd6f82648739f4c8df 100644 (file)
@@ -24,13 +24,12 @@ 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.PrintCellComments;
+import org.apache.poi.xssf.XSSFITestDataProvider;
 
 /**
  * Tests for {@link XSSFPrintSetup}
  */
 public class TestXSSFPrintSetup extends TestCase {
-
-
     public void testSetGetPaperSize() {
         CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
         CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -206,5 +205,47 @@ public class TestXSSFPrintSetup extends TestCase {
         printSetup.setCopies((short) 15);
         assertEquals(15, pSetup.getCopies());
     }
+    
+    public void testSetSaveRead() throws Exception {
+       XSSFWorkbook wb = new XSSFWorkbook();
+       XSSFSheet s1 = wb.createSheet();
+       assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+       
+       XSSFPrintSetup print = s1.getPrintSetup();
+       assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+       
+       print.setCopies((short)3);
+       print.setLandscape(true);
+       assertEquals(3, print.getCopies());
+       assertEquals(true, print.getLandscape());
+       
+       XSSFSheet s2 = wb.createSheet();
+       assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+       
+       // Round trip and check
+       wb = XSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+       
+       s1 = wb.getSheetAt(0);
+       s2 = wb.getSheetAt(1);
+       
+       assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+       assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+       
+       print = s1.getPrintSetup();
+       assertEquals(3, print.getCopies());
+       assertEquals(true, print.getLandscape());
+    }
 
+    /**
+     * Open a file with print settings, save and check.
+     * Then, change, save, read, check
+     */
+    public void testRoundTrip() {
+       // TODO
+    }
 }