poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1659785 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/streaming/SXSSFSheet.java testcases/org/apache/poi/xssf/streaming/TestOutlining.java
Date Sat, 14 Feb 2015 12:46:16 GMT
Author: centic
Date: Sat Feb 14 12:46:16 2015
New Revision: 1659785

URL: http://svn.apache.org/r1659785
Log:
Bug 57459: Add method in SXSSFSheet to directly set row OutLineLevel

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1659785&r1=1659784&r2=1659785&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Sat Feb 14 12:46:16
2015
@@ -1134,10 +1134,38 @@ public class SXSSFSheet implements Sheet
             if(level > outlineLevelRow) outlineLevelRow = level;
         }
 
+        setWorksheetOutlineLevelRow();
+    }
+    
+    /**
+     * Set row groupings (like groupRow) in a stream-friendly manner
+     *
+     * <p>
+     *    groupRows requires all rows in the group to be in the current window.
+     *    This is not always practical.  Instead use setRowOutlineLevel to 
+     *    explicitly set the group level.  Level 1 is the top level group, 
+     *    followed by 2, etc.  It is up to the user to ensure that level 2
+     *    groups are correctly nested under level 1, etc.
+     * </p>
+     *
+     * @param rownum    index of row to update (0-based)
+     * @param level     outline level (> 0)
+     */
+    public void setRowOutlineLevel(int rownum, int level)
+    {
+        SXSSFRow row = _rows.get(new Integer(rownum));
+        row.setOutlineLevel(level);
+        if(level > 0 && level > outlineLevelRow) {
+            outlineLevelRow = level;
+            setWorksheetOutlineLevelRow();
+        }
+    }
+
+    private void setWorksheetOutlineLevelRow() {
         CTWorksheet ct = _sh.getCTWorksheet();
         CTSheetFormatPr pr = ct.isSetSheetFormatPr() ?
-                ct.getSheetFormatPr() :
-                ct.addNewSheetFormatPr();
+            ct.getSheetFormatPr() :
+            ct.addNewSheetFormatPr();
         if(outlineLevelRow > 0) pr.setOutlineLevelRow((short)outlineLevelRow);
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java?rev=1659785&r1=1659784&r2=1659785&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestOutlining.java Sat Feb
14 12:46:16 2015
@@ -110,7 +110,7 @@ public final class TestOutlining extends
 		wb2.close();
 	}
 	
-    public void testOutlineGetters() throws IOException {
+    public void testOutlineGettersHSSF() throws IOException {
         HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
         HSSFSheet hssfSheet = hssfWorkbook.createSheet();
         hssfSheet.createRow(0);
@@ -127,7 +127,9 @@ public final class TestOutlining extends
         assertEquals(2, hssfSheet.getRow(3).getOutlineLevel());
         assertEquals(0, hssfSheet.getRow(4).getOutlineLevel());
         hssfWorkbook.close();
-
+    }
+    
+    public void testOutlineGettersXSSF() throws IOException {
         XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
         XSSFSheet xssfSheet = xssfWorkbook.createSheet();
         xssfSheet.createRow(0);
@@ -144,7 +146,9 @@ public final class TestOutlining extends
         assertEquals(2, xssfSheet.getRow(3).getOutlineLevel());
         assertEquals(0, xssfSheet.getRow(4).getOutlineLevel());
         xssfWorkbook.close();
-
+    }
+    
+    public void testOutlineGettersSXSSF() throws IOException {
         SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
         Sheet sxssfSheet = sxssfWorkbook.createSheet();
         sxssfSheet.createRow(0);
@@ -152,6 +156,17 @@ public final class TestOutlining extends
         sxssfSheet.createRow(2);
         sxssfSheet.createRow(3);
         sxssfSheet.createRow(4);
+        sxssfSheet.createRow(5);
+        
+        // nothing happens with empty row-area
+        sxssfSheet.groupRow(1, 0);
+        assertEquals(0, sxssfSheet.getRow(0).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(1).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(2).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(3).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(4).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(5).getOutlineLevel());
+        
         sxssfSheet.groupRow(1, 3);
         sxssfSheet.groupRow(2, 3);
 
@@ -160,6 +175,49 @@ public final class TestOutlining extends
         assertEquals(2, sxssfSheet.getRow(2).getOutlineLevel());
         assertEquals(2, sxssfSheet.getRow(3).getOutlineLevel());
         assertEquals(0, sxssfSheet.getRow(4).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(5).getOutlineLevel());
+        
+        // add tests for direct setting - add row 4 to deepest group
+        ((SXSSFSheet)sxssfSheet).setRowOutlineLevel(4, 2);
+        assertEquals(0, sxssfSheet.getRow(0).getOutlineLevel());
+        assertEquals(1, sxssfSheet.getRow(1).getOutlineLevel());
+        assertEquals(2, sxssfSheet.getRow(2).getOutlineLevel());
+        assertEquals(2, sxssfSheet.getRow(3).getOutlineLevel());
+        assertEquals(2, sxssfSheet.getRow(4).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(5).getOutlineLevel());
+        
+        sxssfWorkbook.dispose();
+        sxssfWorkbook.close();
+    }
+    
+    public void testOutlineGettersSXSSFSetOutlineLevel() throws IOException {
+        SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
+        Sheet sxssfSheet = sxssfWorkbook.createSheet();
+        sxssfSheet.createRow(0);
+        sxssfSheet.createRow(1);
+        sxssfSheet.createRow(2);
+        sxssfSheet.createRow(3);
+        sxssfSheet.createRow(4);
+        sxssfSheet.createRow(5);
+    
+        // what happens with level below 1
+        ((SXSSFSheet)sxssfSheet).setRowOutlineLevel(0, -2);
+        assertEquals(-2, sxssfSheet.getRow(0).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(1).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(2).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(3).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(4).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(5).getOutlineLevel());
+
+        // add tests for direct setting
+        ((SXSSFSheet)sxssfSheet).setRowOutlineLevel(4, 2);
+        assertEquals(-2, sxssfSheet.getRow(0).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(1).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(2).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(3).getOutlineLevel());
+        assertEquals(2, sxssfSheet.getRow(4).getOutlineLevel());
+        assertEquals(0, sxssfSheet.getRow(5).getOutlineLevel());
+        
         sxssfWorkbook.dispose();
         sxssfWorkbook.close();
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message