--- HSSFRow.java Sun Sep 21 21:50:21 2008 700027 +++ HSSFRow.java Mon Sep 29 18:28:53 2008 @@ -35, +35,7 @@ -public final class HSSFRow implements Comparable { +public class HSSFRow implements Comparable { + protected class BookNSheet + { + protected HSSFWorkbook book; + protected HSSFSheet sheet; + int row; + } @@ -57,0 +64,18 @@ +// /** +// * Creates new HSSFRow from scratch. Only HSSFSheet should do this. +// * +// * @param book low-level Workbook object containing the sheet that contains this row +// * @param sheet low-level Sheet object that contains this Row +// * @param rowNum the row number of this row (0 based) +// * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) +// */ +// HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum) +// { +// this.rowNum = rowNum; +// this.book = book; +// this.sheet = sheet; +// row = new RowRecord(rowNum); +// +// setRowNum(rowNum); +// } + @@ -59, +83,2 @@ - * Creates new HSSFRow from scratch. Only HSSFSheet should do this. + * Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do + * this. HSSFSheet uses this when an existing file is read in. @@ -63, +88, @@ - * @param rowNum the row number of this row (0 based) + * @param record the low level api object this row should represent @@ -66, +91, @@ - HSSFRow(HSSFWorkbook book, HSSFSheet sheet, int rowNum) + protected HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) @@ -68, +92,0 @@ - this.rowNum = rowNum; @@ -71, +95, @@ - row = new RowRecord(rowNum); + row = record; @@ -73, +97, @@ - setRowNum(rowNum); + setRowNum(record.getRowNumber()); @@ -77,2 +101,5 @@ - * Creates an HSSFRow from a low level RowRecord object. Only HSSFSheet should do - * this. HSSFSheet uses this when an existing file is read in. + * You can now also create a new HSSFRow with this public constructor, + * not having to use HSSFSheet.createRow. + * This makes it possible to derive classes from HSSFRow + * (it is no longer ) and to construct objects of the derived + * classes which can be used like the original ones. @@ -80,4 +107,2 @@ - * @param book low-level Workbook object containing the sheet that contains this row - * @param sheet low-level Sheet object that contains this Row - * @param record the low level api object this row should represent - * @see org.apache.poi.hssf.usermodel.HSSFSheet#createRow(int) + * @param sheet + * @param rowNum @@ -85, +110, @@ - HSSFRow(HSSFWorkbook book, HSSFSheet sheet, RowRecord record) + public HSSFRow(HSSFSheet sheet, int rowNum) @@ -87, +111,0 @@ - this.book = book; @@ -89, +113,3 @@ - row = record; + this.rowNum = rowNum; + this.book = sheet.workbook; + row = new RowRecord(rowNum); @@ -91, +117,2 @@ - setRowNum(record.getRowNumber()); + setRowNum(rowNum); + sheet.initNewRow (this); @@ -92,0 +120, @@ + @@ -103,0 +132,2 @@ + * You can verride this in derived classes for custom derived cell classes, + * but it's not necessary, as createCell (int, int) is used internally @@ -105, +135, @@ - * @param column - the column number this cell represents + * @param columnIndex - the column number this cell represents @@ -124,0 +155, @@ + * ## Override this in derived classes for custom derived cell classes ## @@ -133, +164,6 @@ - HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), (short)columnIndex, type); +// HSSFCell cell = new HSSFCell(book, sheet, getRowNum(), (short)columnIndex, type); +// +// addCell(cell); +// sheet.getSheet().addValueRecord(getRowNum(), cell.getCellValueRecord()); + return new HSSFCell (this, columnIndex, type); + } @@ -134,0 +171,20 @@ + /** + * Service function for the new public HSSFCell Constructor + * @return a BookNSheet Object which contains Workbook, Sheet ans Row Idx + * of this row + */ + BookNSheet getPrivateParts () + { + BookNSheet pp = new BookNSheet (); + pp.book = this.book; + pp.sheet = this.sheet; + pp.row = getRowNum(); + return pp; + } + + /** + * Last phase of the initialzation of a newly constructed HSSFCell + * @param cell + */ + void initNewCell (HSSFCell cell) + { @@ -137, +192,0 @@ - return cell; @@ -187,0 +243,15 @@ + * This method is invoked indirectly by all HSSFWorkbook constructors with + * IO access when a new cell must be created. + * ## Override this in derived classes for custom derived cell classes ## + * Just pass on the parameters to an HSSFCell-derived-class constructor + * @param pBook - The HSSF Workbook object associated with the row + * @param pSheet - The HSSF Sheet which contains the row + * @param pCell - The low level record from which the cell is to be created + * @return a new HSSFCell + */ + protected HSSFCell HSSFCellFactory (HSSFWorkbook pBook, HSSFSheet pSheet + ,CellValueRecordInterface pCell) + { + return new HSSFCell (pBook, pSheet, pCell); + } + /** @@ -194, +264, @@ - HSSFCell hcell = new HSSFCell(book, sheet, cell); + HSSFCell hcell = HSSFCellFactory (book, sheet, cell);