implements Comparable
{
public final static short sid = 0x208;
+
+ /** The maximum row number that excel can handle (zero bazed) ie 65536 rows is
+ * max number of rows.
+ */
+ public final static int MAX_ROW_NUMBER = 65535;
+
//private short field_1_row_number;
private int field_1_row_number;
private short field_2_first_col;
//protected HSSFRow(Workbook book, Sheet sheet, short rowNum)
protected HSSFRow(Workbook book, Sheet sheet, int rowNum)
{
- this.rowNum = rowNum;
cells = new HashMap(10); // new ArrayList(INITIAL_CAPACITY);
this.book = book;
this.sheet = sheet;
row.setLastCol((short) -1);
row.setFirstCol((short) -1);
- // row.setRowNumber(rowNum);
setRowNum(rowNum);
}
protected HSSFRow(Workbook book, Sheet sheet, RowRecord record)
{
- //this.rowNum = rowNum;
cells = new HashMap(); // ArrayList(INITIAL_CAPACITY);
this.book = book;
this.sheet = sheet;
row = record;
- // row.setHeight(record.getHeight());
- // row.setRowNumber(rowNum);
setRowNum(record.getRowNumber());
-
-// addColumns(book, sheet, record);
}
/**
/**
* set the row number of this row.
* @param rowNum the row number (0-based)
+ * @throws IndexOutOfBoundsException if the row number is not within the range 0-65535.
*/
//public void setRowNum(short rowNum)
public void setRowNum(int rowNum)
{
+ if ((rowNum < 0) || (rowNum > RowRecord.MAX_ROW_NUMBER))
+ throw new IndexOutOfBoundsException("Row number must be between 0 and "+RowRecord.MAX_ROW_NUMBER+", was <"+rowNum+">");
this.rowNum = rowNum;
if (row != null)
{
}
+
+ public void testRowBounds()
+ throws Exception
+ {
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet();
+ //Test low row bound
+ HSSFRow row = sheet.createRow( (short) 0);
+ //Test low row bound exception
+ boolean caughtException = false;
+ try {
+ row = sheet.createRow(-1);
+ } catch (IndexOutOfBoundsException ex) {
+ caughtException = true;
+ }
+ assertTrue(caughtException);
+ //Test high row bound
+ row = sheet.createRow(65535);
+ //Test high row bound exception
+ caughtException = false;
+ try {
+ row = sheet.createRow(65536);
+ } catch (IndexOutOfBoundsException ex) {
+ caughtException = true;
+ }
+ assertTrue(caughtException);
+ }
+
}