BUG 27496: get/setPageBreak and get/getColumnBreak now work correctly if a template excel file is loaded which does not contain PaneRecords is loaded.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@441652 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
373e9d5613
commit
19ced80f3c
@ -2667,6 +2667,11 @@ public class Sheet implements Model
|
|||||||
* @param 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);
|
rowBreaks.addBreak((short)row, fromCol, toCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2675,6 +2680,8 @@ public class Sheet implements Model
|
|||||||
* @param row
|
* @param row
|
||||||
*/
|
*/
|
||||||
public void removeRowBreak(int row) {
|
public void removeRowBreak(int row) {
|
||||||
|
if (rowBreaks == null)
|
||||||
|
throw new IllegalArgumentException("Sheet does not define any row breaks");
|
||||||
rowBreaks.removeBreak((short)row);
|
rowBreaks.removeBreak((short)row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2684,7 +2691,7 @@ public class Sheet implements Model
|
|||||||
* @return true if the specified row has a page break
|
* @return true if the specified row has a page break
|
||||||
*/
|
*/
|
||||||
public boolean isRowBroken(int row) {
|
public boolean isRowBroken(int row) {
|
||||||
return rowBreaks.getBreak((short)row) != null;
|
return (rowBreaks == null) ? false : rowBreaks.getBreak((short)row) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2692,6 +2699,11 @@ public class Sheet implements Model
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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);
|
colBreaks.addBreak(column, fromRow, toRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2700,6 +2712,9 @@ public class Sheet implements Model
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void removeColumnBreak(short column) {
|
public void removeColumnBreak(short column) {
|
||||||
|
if (colBreaks == null)
|
||||||
|
throw new IllegalArgumentException("Sheet does not define any column breaks");
|
||||||
|
|
||||||
colBreaks.removeBreak(column);
|
colBreaks.removeBreak(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2709,7 +2724,7 @@ public class Sheet implements Model
|
|||||||
* @return true if the specified column has a page break
|
* @return true if the specified column has a page break
|
||||||
*/
|
*/
|
||||||
public boolean isColumnBroken(short column) {
|
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
|
* @return the number of row page breaks
|
||||||
*/
|
*/
|
||||||
public int getNumRowBreaks(){
|
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
|
* @return the number of column page breaks
|
||||||
*/
|
*/
|
||||||
public int getNumColumnBreaks(){
|
public int getNumColumnBreaks(){
|
||||||
return (int)colBreaks.getNumBreaks();
|
return (colBreaks == null) ? 0 : (int)colBreaks.getNumBreaks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
|
public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
|
||||||
|
@ -1204,11 +1204,13 @@ public class HSSFSheet
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the horizontal page breaks
|
* 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(){
|
public int[] getRowBreaks(){
|
||||||
//we can probably cache this information, but this should be a sparsely used function
|
//we can probably cache this information, but this should be a sparsely used function
|
||||||
int[] returnValue = new int[sheet.getNumRowBreaks()];
|
int count = sheet.getNumRowBreaks();
|
||||||
|
if (count > 0) {
|
||||||
|
int[] returnValue = new int[count];
|
||||||
Iterator iterator = sheet.getRowBreaks();
|
Iterator iterator = sheet.getRowBreaks();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@ -1217,14 +1219,18 @@ public class HSSFSheet
|
|||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the vertical page breaks
|
* 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(){
|
public short[] getColumnBreaks(){
|
||||||
//we can probably cache this information, but this should be a sparsely used function
|
//we can probably cache this information, but this should be a sparsely used function
|
||||||
short[] returnValue = new short[sheet.getNumColumnBreaks()];
|
int count = sheet.getNumColumnBreaks();
|
||||||
|
if (count > 0) {
|
||||||
|
short[] returnValue = new short[count];
|
||||||
Iterator iterator = sheet.getColumnBreaks();
|
Iterator iterator = sheet.getColumnBreaks();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@ -1233,6 +1239,8 @@ public class HSSFSheet
|
|||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user