]> source.dussan.org Git - poi.git/commitdiff
Fix for bug #43058 - handle setting row grouping for sheets that lacked gutsrecords...
authorNick Burch <nick@apache.org>
Wed, 9 Jan 2008 13:37:06 +0000 (13:37 +0000)
committerNick Burch <nick@apache.org>
Wed, 9 Jan 2008 13:37:06 +0000 (13:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610384 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/Sheet.java
src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/testcases/org/apache/poi/hssf/data/NoGutsRecords.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java

index 79eb0e91401889c1789e9a0963fb1151822da6b7..4548b63bc7d561f32c4a0416e4615e7835f9ec7d 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
             <action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
             <action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
index 37383c81698e2c3aabeaa4a61f6962e3a8a967ea..5a0461620ca0307a9e7d6b3216cad1c135a2f58c 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2008-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">43058 - Support setting row grouping on files from CR IX, which lack GutsRecords</action>
             <action dev="POI-DEVELOPERS" type="fix">31795 - Support cloning of sheets with certain drawing objects on them</action>
             <action dev="POI-DEVELOPERS" type="fix">43902 - Don't consider merged regions when auto-sizing columns</action>
             <action dev="POI-DEVELOPERS" type="fix">42464 - Avoid "Expected ExpPtg to be converted from Shared to Non-Shared Formula" on large, formula heavy worksheets</action>
index ff18f4636b18f8d73d3e5325d7b3b89de3108da9..c3f93b0a0149f18643bf48a48648212c7f5c38d5 100644 (file)
@@ -3144,7 +3144,13 @@ public class Sheet implements Model
             maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel);
         }
 
+        // Grab the guts record, adding if needed
         GutsRecord guts = (GutsRecord) findFirstRecordBySid( GutsRecord.sid );
+        if(guts == null) {
+               guts = new GutsRecord();
+               records.add(guts);
+        }
+        // Set the levels onto it
         guts.setRowLevelMax( (short) ( maxLevel + 1 ) );
         guts.setLeftRowGutter( (short) ( 29 + (12 * (maxLevel)) ) );
     }
index 423b023af1a41abb67e7a9386d1798364898df8b..6cea11fa0a3e4dc46df56aae5a593a4d0f8952e9 100644 (file)
@@ -223,6 +223,16 @@ public class HSSFRow
     {
         return rowNum;
     }
+    
+    /**
+     * Returns the rows outline level. Increased as you
+     *  put it into more groups (outlines), reduced as
+     *  you take it out of them.
+     * TODO - Should this really be public?
+     */
+    protected int getOutlineLevel() {
+       return row.getOutlineLevel();
+    }
 
     /**
      * used internally to add a cell.
diff --git a/src/testcases/org/apache/poi/hssf/data/NoGutsRecords.xls b/src/testcases/org/apache/poi/hssf/data/NoGutsRecords.xls
new file mode 100644 (file)
index 0000000..c4340f6
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/NoGutsRecords.xls differ
index 9a6f9dca000cc3247491b93b61327dd0c2681e67..714cb8d2c31ab0fd3441e0affc5799a5823e0399 100644 (file)
@@ -309,6 +309,104 @@ public class TestHSSFSheet
         assertEquals(1, sheetLS.getPrintSetup().getCopies());
     }
     
+    public void testGroupRows() throws Exception {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet s = workbook.createSheet();
+        HSSFRow r1 = s.createRow(0);
+        HSSFRow r2 = s.createRow(1);
+        HSSFRow r3 = s.createRow(2);
+        HSSFRow r4 = s.createRow(3);
+        HSSFRow r5 = s.createRow(4);
+        
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(0, r3.getOutlineLevel());
+        assertEquals(0, r4.getOutlineLevel());
+        assertEquals(0, r5.getOutlineLevel());
+        
+        s.groupRow(2,3);
+        
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(1, r3.getOutlineLevel());
+        assertEquals(1, r4.getOutlineLevel());
+        assertEquals(0, r5.getOutlineLevel());
+        
+        // Save and re-open
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        workbook.write(baos);
+        workbook = new HSSFWorkbook(
+                       new ByteArrayInputStream(baos.toByteArray())
+        );
+        
+        s = workbook.getSheetAt(0);
+        r1 = s.getRow(0);
+        r2 = s.getRow(1);
+        r3 = s.getRow(2);
+        r4 = s.getRow(3);
+        r5 = s.getRow(4);
+        
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(1, r3.getOutlineLevel());
+        assertEquals(1, r4.getOutlineLevel());
+        assertEquals(0, r5.getOutlineLevel());
+    }
+    
+    public void testGroupRowsExisting() throws Exception {
+        String filename = System.getProperty("HSSF.testdata.path");
+        filename = filename + "/NoGutsRecords.xls";
+        HSSFWorkbook workbook = 
+               new HSSFWorkbook(new FileInputStream(filename));
+        
+        HSSFSheet s = workbook.getSheetAt(0);
+        HSSFRow r1 = s.getRow(0);
+        HSSFRow r2 = s.getRow(1);
+        HSSFRow r3 = s.getRow(2);
+        HSSFRow r4 = s.getRow(3);
+        HSSFRow r5 = s.getRow(4);
+        HSSFRow r6 = s.getRow(5);
+
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(0, r3.getOutlineLevel());
+        assertEquals(0, r4.getOutlineLevel());
+        assertEquals(0, r5.getOutlineLevel());
+        assertEquals(0, r6.getOutlineLevel());
+        
+        // This used to complain about lacking guts records
+        s.groupRow(2, 4);
+        
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(1, r3.getOutlineLevel());
+        assertEquals(1, r4.getOutlineLevel());
+        assertEquals(1, r5.getOutlineLevel());
+        assertEquals(0, r6.getOutlineLevel());
+        
+        // Save and re-open
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        workbook.write(baos);
+        workbook = new HSSFWorkbook(
+                       new ByteArrayInputStream(baos.toByteArray())
+        );
+        
+        s = workbook.getSheetAt(0);
+        r1 = s.getRow(0);
+        r2 = s.getRow(1);
+        r3 = s.getRow(2);
+        r4 = s.getRow(3);
+        r5 = s.getRow(4);
+        r6 = s.getRow(5);
+        
+        assertEquals(0, r1.getOutlineLevel());
+        assertEquals(0, r2.getOutlineLevel());
+        assertEquals(1, r3.getOutlineLevel());
+        assertEquals(1, r4.getOutlineLevel());
+        assertEquals(1, r5.getOutlineLevel());
+        assertEquals(0, r6.getOutlineLevel());
+    }
+    
        /**
         * Test that the ProtectRecord is included when creating or cloning a sheet
         */