]> source.dussan.org Git - poi.git/commitdiff
Fix bug #49253 - When setting repeating rows and columns for XSSF, don't break the...
authorNick Burch <nick@apache.org>
Fri, 18 Mar 2011 16:06:10 +0000 (16:06 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Mar 2011 16:06:10 +0000 (16:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1082961 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 3ee716b13532f3ba57ebc415599287b7e11fc56b..fa77fbdf19e034a24421a913dcdf3ab950948a3d 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta2" date="2011-??-??">
+           <action dev="poi-developers" type="fix">49253 - When setting repeating rows and columns for XSSF, don't break the print settings if they were already there</action>
            <action dev="poi-developers" type="fix">49219 - ExternalNameRecord support for DDE Link entries without an operation</action>
            <action dev="poi-developers" type="fix">50846 - More XSSFColor theme improvements, this time for Cell Borders</action>
            <action dev="poi-developers" type="fix">50939 - ChartEndObjectRecord is supposed to have 6 bytes at the end, but handle it not</action>
index b7ae0315025aac3b825177acf9ab98a9e233c056..f4512914df44490c14224d40a99e6b1bce3149d0 100644 (file)
@@ -1018,8 +1018,17 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
         name.setRefersToFormula(reference);
 
-        XSSFPrintSetup printSetup = sheet.getPrintSetup();
-        printSetup.setValidSettings(false);
+        // If the print setup isn't currently defined, then add it
+        //  in but without printer defaults
+        // If it's already there, leave it as-is!
+        CTWorksheet ctSheet = sheet.getCTWorksheet();
+        if(ctSheet.isSetPageSetup() && ctSheet.isSetPageMargins()) {
+           // Everything we need is already there
+        } else {
+           // Have initial ones put in place
+           XSSFPrintSetup printSetup = sheet.getPrintSetup();
+           printSetup.setValidSettings(false);
+        }
     }
 
     private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {
index 710ba2c01f4ff949a7dda582848dae6587345b4f..2ab17d1ad1417b146676c6268cdcea3032ede67b 100644 (file)
@@ -892,4 +892,46 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
        assertEquals("Tabella1", t.getDisplayName());
        assertEquals("A1:C3", t.getCTTable().getRef());
     }
+    
+    /**
+     * Setting repeating rows and columns shouldn't break
+     *  any print settings that were there before
+     */
+    public void test49253() throws Exception {
+       XSSFWorkbook wb1 = new XSSFWorkbook();
+       XSSFWorkbook wb2 = new XSSFWorkbook();
+       
+       // No print settings before repeating
+       XSSFSheet s1 = wb1.createSheet(); 
+       assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+       
+       wb1.setRepeatingRowsAndColumns(0, 2, 3, 1, 2);
+       
+       assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+       
+       XSSFPrintSetup ps1 = s1.getPrintSetup();
+       assertEquals(false, ps1.getValidSettings());
+       assertEquals(false, ps1.getLandscape());
+       
+       
+       // Had valid print settings before repeating
+       XSSFSheet s2 = wb2.createSheet();
+       XSSFPrintSetup ps2 = s2.getPrintSetup();
+       assertEquals(true, s2.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+       
+       ps2.setLandscape(false);
+       assertEquals(true, ps2.getValidSettings());
+       assertEquals(false, ps2.getLandscape());
+       
+       wb2.setRepeatingRowsAndColumns(0, 2, 3, 1, 2);
+       
+       ps2 = s2.getPrintSetup();
+       assertEquals(true, s2.getCTWorksheet().isSetPageSetup());
+       assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+       assertEquals(true, ps2.getValidSettings());
+       assertEquals(false, ps2.getLandscape());
+    }
 }