]> source.dussan.org Git - poi.git/commitdiff
BUG 27496: get/setPageBreak and get/getColumnBreak now work correctly if a template...
authorJason Height <jheight@apache.org>
Fri, 8 Sep 2006 21:09:48 +0000 (21:09 +0000)
committerJason Height <jheight@apache.org>
Fri, 8 Sep 2006 21:09:48 +0000 (21:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@441652 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/Sheet.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java

index 892f6278967534ab2d90971a9b02ed1cfe27999b..e71bad09781a21c3d23634f46241d7d418a9ce5d 100644 (file)
@@ -2666,7 +2666,12 @@ public class Sheet implements Model
      * Sets a page break at the indicated row
      * @param row
      */
-    public void setRowBreak(int row, short fromCol, short toCol) {     
+    public void setRowBreak(int row, short fromCol, short toCol) { 
+       if (rowBreaks == null) {
+            int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
+            rowBreaks = new PageBreakRecord(PageBreakRecord.HORIZONTAL_SID);
+            records.add(loc, rowBreaks);
+       }
        rowBreaks.addBreak((short)row, fromCol, toCol);
     }
 
@@ -2675,6 +2680,8 @@ public class Sheet implements Model
      * @param row
      */
     public void removeRowBreak(int row) {
+       if (rowBreaks == null)
+               throw new IllegalArgumentException("Sheet does not define any row breaks");
        rowBreaks.removeBreak((short)row);
     }
 
@@ -2684,14 +2691,19 @@ public class Sheet implements Model
      * @return true if the specified row has a page break
      */
     public boolean isRowBroken(int row) {
-       return rowBreaks.getBreak((short)row) != null;
+       return (rowBreaks == null) ? false : rowBreaks.getBreak((short)row) != null;
     }
 
     /**
      * Sets a page break at the indicated column
      *
      */
-    public void setColumnBreak(short column, short fromRow, short toRow) {     
+    public void setColumnBreak(short column, short fromRow, short toRow) {
+       if (colBreaks == null) {
+            int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
+            colBreaks = new PageBreakRecord(PageBreakRecord.VERTICAL_SID);
+            records.add(loc, colBreaks);
+       }       
        colBreaks.addBreak(column, fromRow, toRow);
     }
 
@@ -2700,6 +2712,9 @@ public class Sheet implements Model
      *
      */
     public void removeColumnBreak(short column) {
+       if (colBreaks == null)
+               throw new IllegalArgumentException("Sheet does not define any column breaks");
+       
        colBreaks.removeBreak(column);
     }
 
@@ -2709,7 +2724,7 @@ public class Sheet implements Model
      * @return true if the specified column has a page break
      */
     public boolean isColumnBroken(short column) {
-       return colBreaks.getBreak(column) != null;
+       return (colBreaks == null) ? false : colBreaks.getBreak(column) != null;
     }
     
     /**
@@ -2745,7 +2760,7 @@ public class Sheet implements Model
      * @return the number of row page breaks
      */
     public int getNumRowBreaks(){
-       return (int)rowBreaks.getNumBreaks();
+       return (rowBreaks == null) ? 0 : (int)rowBreaks.getNumBreaks();
     }
     
     /**
@@ -2761,7 +2776,7 @@ public class Sheet implements Model
      * @return the number of column page breaks
      */
     public int getNumColumnBreaks(){
-       return (int)colBreaks.getNumBreaks();
+       return (colBreaks == null) ? 0 : (int)colBreaks.getNumBreaks();
     }
 
     public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
index 99a2b5fef36af5a4d6908fb98b6d7d14e09cd139..006d096d05f9c0c5d7f4c2466da3840f42451627 100644 (file)
@@ -1204,34 +1204,42 @@ public class HSSFSheet
     
     /**
      * Retrieves all the horizontal page breaks
-     * @return all the horizontal page breaks
+     * @return all the horizontal page breaks, or null if there are no row page breaks
      */
     public int[] getRowBreaks(){
-       //we can probably cache this information, but this should be a sparsely used function 
-       int[] returnValue = new int[sheet.getNumRowBreaks()];
-       Iterator iterator = sheet.getRowBreaks();
-       int i = 0;
-       while (iterator.hasNext()) {
+       //we can probably cache this information, but this should be a sparsely used function
+       int count = sheet.getNumRowBreaks();
+       if (count > 0) {
+         int[] returnValue = new int[count];
+         Iterator iterator = sheet.getRowBreaks();
+         int i = 0;
+         while (iterator.hasNext()) {
                PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
                returnValue[i++] = (int)breakItem.main;
+         }
+         return returnValue;
        }
-       return returnValue;
+       return null;
     }
 
     /**
      * Retrieves all the vertical page breaks
-     * @return all the vertical page breaks
+     * @return all the vertical page breaks, or null if there are no column page breaks
      */
     public short[] getColumnBreaks(){
        //we can probably cache this information, but this should be a sparsely used function 
-       short[] returnValue = new short[sheet.getNumColumnBreaks()];
-       Iterator iterator = sheet.getColumnBreaks();
-       int i = 0;
-       while (iterator.hasNext()) {
+       int count = sheet.getNumColumnBreaks();
+       if (count > 0) {
+         short[] returnValue = new short[count];
+         Iterator iterator = sheet.getColumnBreaks();
+         int i = 0;
+         while (iterator.hasNext()) {
                PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
                returnValue[i++] = breakItem.main;
+         }
+         return returnValue;
        }
-       return returnValue;
+       return null;
     }