]> source.dussan.org Git - poi.git/commitdiff
Bug 48314 - Fixed setting column and row breaks in XSSF, also updated javadocs
authorYegor Kozlov <yegor@apache.org>
Fri, 24 Jun 2011 12:15:16 +0000 (12:15 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 24 Jun 2011 12:15:16 +0000 (12:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1139266 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index 31ad081831037919a95fa3dca651475d38544e32..5e268167d72ffdb2493fdbcb4e9b75dee7abcb86 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">48314 - Fixed setting column and row breaks in XSSF</action>
            <action dev="poi-developers" type="add">51424 - Ignore exceptions in ParagraphSprmUncompressor</action>
            <action dev="poi-developers" type="fix">51415 - Fixed Workbook.createSheet(sheetName) to truncate names longer than 31 characters</action>
            <action dev="poi-developers" type="fix">51332 - Fixed internal IDs of shapes generated by HSSFPatriarch when there are more than 1023 drawing objects </action>
index 92b5220356870ddb796f6b259d3bf46c5e66fd45..59ef00cfe416dd5df56829d2bca4915392b43e25 100644 (file)
@@ -1506,7 +1506,14 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
 
     /**
      * Sets a page break at the indicated row
-     * @param row FIXME: Document this!
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
+     *
+     * @param row the row to break, inclusive
      */
     public void setRowBreak(int row) {
         validateRow(row);
@@ -1545,8 +1552,15 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
 
 
     /**
-     * Sets a page break at the indicated column
-     * @param column
+     * Sets a page break at the indicated column.
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
+     *
+     * @param column the column to break, inclusive
      */
     public void setColumnBreak(int column) {
         validateColumn((short)column);
index 090c25150d496e9db0bcac0747a6c27ede267f30..4b82c08c8c27816da114f505c41a61c89d220e67 100644 (file)
@@ -673,7 +673,14 @@ public interface Sheet extends Iterable<Row> {
 
     /**
      * Sets a page break at the indicated row
-     * @param row FIXME: Document this!
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
+     *
+     * @param row the row to break, inclusive
      */
     void setRowBreak(int row);
 
@@ -703,8 +710,15 @@ public interface Sheet extends Iterable<Row> {
     int[] getColumnBreaks();
 
     /**
-     * Sets a page break at the indicated column
-     * @param column
+     * Sets a page break at the indicated column.
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
+     *
+     * @param column the column to break, inclusive
      */
     void setColumnBreak(int column);
 
index 6ebd49432e358085c398c341f7e2e4ed2cdea582..df3d9e455e3da66ab619e0447ea26032838306b1 100644 (file)
@@ -622,18 +622,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         int[] breaks = new int[brkArray.length];
         for (int i = 0 ; i < brkArray.length ; i++) {
             CTBreak brk = brkArray[i];
-            breaks[i] = (int)brk.getId();
+            breaks[i] = (int)brk.getId() - 1;
         }
         return breaks;
     }
 
-    private CTPageBreak getSheetTypeColumnBreaks() {
-        if (worksheet.getColBreaks() == null) {
-            worksheet.setColBreaks(CTPageBreak.Factory.newInstance());
-        }
-        return worksheet.getColBreaks();
-    }
-
     /**
      * Get the actual column width (in units of 1/256th of a character width )
      *
@@ -1077,7 +1070,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         int[] breaks = new int[brkArray.length];
         for (int i = 0 ; i < brkArray.length ; i++) {
             CTBreak brk = brkArray[i];
-            breaks[i] = (int)brk.getId();
+            breaks[i] = (int)brk.getId() - 1;
         }
         return breaks;
     }
@@ -1383,12 +1376,25 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
 
     /**
      * Sets a page break at the indicated row
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
+     *
+     * @param row the row to break, inclusive
      */
     public void setRowBreak(int row) {
         CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
         if (! isRowBroken(row)) {
             CTBreak brk = pgBreak.addNewBrk();
-            brk.setId(row);
+            brk.setId(row + 1); // this is id of the row element which is 1-based: <row r="1" ... >
+            brk.setMan(true);
+            brk.setMax(SpreadsheetVersion.EXCEL2007.getLastColumnIndex()); //end column of the break
+
+            pgBreak.setCount(pgBreak.sizeOfBrkArray());
+            pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
         }
     }
 
@@ -1397,10 +1403,16 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
      */
     @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
     public void removeColumnBreak(int column) {
-        CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
+        if (!worksheet.isSetColBreaks()) {
+            // no breaks
+            return;
+        }
+
+        CTPageBreak pgBreak = worksheet.getColBreaks();
+        CTBreak[] brkArray = pgBreak.getBrkArray();
         for (int i = 0 ; i < brkArray.length ; i++) {
-            if (brkArray[i].getId() == column) {
-                getSheetTypeColumnBreaks().removeBrk(i);
+            if (brkArray[i].getId() == (column + 1)) {
+                pgBreak.removeBrk(i);
             }
         }
     }
@@ -1452,10 +1464,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
      */
     @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
     public void removeRowBreak(int row) {
-        CTPageBreak pgBreak = worksheet.isSetRowBreaks() ? worksheet.getRowBreaks() : worksheet.addNewRowBreaks();
+        if(!worksheet.isSetRowBreaks()) {
+            return;
+        }
+        CTPageBreak pgBreak = worksheet.getRowBreaks();
         CTBreak[] brkArray = pgBreak.getBrkArray();
         for (int i = 0 ; i < brkArray.length ; i++) {
-            if (brkArray[i].getId() == row) {
+            if (brkArray[i].getId() == (row + 1)) {
                 pgBreak.removeBrk(i);
             }
         }
@@ -1537,14 +1552,26 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
     }
 
     /**
-     * Sets a page break at the indicated column
+     * Sets a page break at the indicated column.
+     * Breaks occur above the specified row and left of the specified column inclusive.
+     *
+     * For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
+     * with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
+     * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part
+     * and rows starting with rownum=4 in the second.
      *
-     * @param column the column to break
+     * @param column the column to break, inclusive
      */
     public void setColumnBreak(int column) {
         if (! isColumnBroken(column)) {
-            CTBreak brk = getSheetTypeColumnBreaks().addNewBrk();
-            brk.setId(column);
+            CTPageBreak pgBreak = worksheet.isSetColBreaks() ? worksheet.getColBreaks() : worksheet.addNewColBreaks();
+            CTBreak brk = pgBreak.addNewBrk();
+            brk.setId(column + 1);  // this is id of the row element which is 1-based: <row r="1" ... >
+            brk.setMan(true);
+            brk.setMax(SpreadsheetVersion.EXCEL2007.getLastRowIndex()); //end row of the break
+
+            pgBreak.setCount(pgBreak.sizeOfBrkArray());
+            pgBreak.setManualBreakCount(pgBreak.sizeOfBrkArray());
         }
     }