--- HSSFSheet.java Mon Sep 29 09:27:14 2008 700026 +++ HSSFSheet.java Mon Sep 29 18:11:21 2008 @@ -61 +61 @@ -public final class HSSFSheet { +public class HSSFSheet { @@ -98,2 +98 @@ - * Creates new HSSFSheet - called by HSSFWorkbook to create a sheet from - * scratch. You should not be calling this from application code (its protected anyhow). + * Creates new HSSFSheet in the given HSSFWorkbook @@ -101,0 +101 @@ + * @param sheetname - Name of new sheet. If => "Sheet" is used @@ -105 +105 @@ - protected HSSFSheet(HSSFWorkbook workbook) + public HSSFSheet(HSSFWorkbook p_workbook, String sheetname) @@ -106,0 +107,5 @@ + this.workbook = p_workbook; + this.book = p_workbook.getWorkbook(); + if (sheetname != null) + if (book.doesContainsSheetName( sheetname, workbook._sheets.size() )) + throw new IllegalArgumentException( "The workbook already contains a sheet of name " + sheetname ); @@ -108,3 +113,8 @@ - rows = new TreeMap(); - this.workbook = workbook; - this.book = workbook.getWorkbook(); + rows = new TreeMap(); // new ArrayList(INITIAL_CAPACITY); + workbook._sheets.add(this); + workbook.setSheetName(workbook._sheets.size() - 1 + ,sheetname==null ? "Sheet" + (workbook._sheets.size() - 1) + : sheetname); + boolean isOnlySheet = workbook._sheets.size() == 1; + setSelected(isOnlySheet); + setActive(isOnlySheet); @@ -119 +129 @@ - * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createSheet() + * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#HSSFWorkbook(DirectoryNode,POIFSFileSystem,boolean) @@ -195,0 +206 @@ + * ## Override this in derived classes for custom derived row classes ## @@ -204 +215,6 @@ - HSSFRow row = new HSSFRow(workbook, this, rownum); + // HSSFRow row = new HSSFRow(workbook, this, rownum); + // + // addRow(row, true); + // return row; + return new HSSFRow (this, rownum); + } @@ -206,2 +222,12 @@ - addRow(row, true); - return row; + /** + * + * Second phase of the initialization of a new HSSFRow + * Cannot be done in because auf necessary intermediate steps + * Could be avoided by giving package access, + * but I didn't want to change that. + * + * @param newrow the HSSFRow to be added + */ + void initNewRow (HSSFRow newrow) + { + addRow(newrow, true); @@ -210,0 +237,14 @@ + * This method is invoked indirectly by all HSSFWorkbook constructors with + * IO access when a new row must be created. + * ## Override this in derived classes for custom derived row classes ## + * Just pass on the parameters to an HSSFRow-derived-class constructor + * @param pBook - The HSSF Workbook object associated with the row + * @param pSheet - The HSSF Sheet which contains the row + * @param pRow - The low level record from which the row is to be created + * @return a new HSSFRow + */ + protected HSSFRow HSSFRowFactory (HSSFWorkbook pBook, HSSFSheet pSheet, RowRecord pRow) + { + return new HSSFRow(pBook, pSheet, pRow); + } + /** @@ -212 +252 @@ - * USed when reading an existing file + * Used when reading an existing file @@ -216 +255,0 @@ - @@ -219 +258 @@ - HSSFRow hrow = new HSSFRow(workbook, this, row); + HSSFRow hrow = HSSFRowFactory (workbook, this, row); @@ -1275 +1314 @@ - sheet.updateFormulasAfterCellShift(shifter, externSheetIndex); + sheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, externSheetIndex); @@ -1284 +1323 @@ - otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx); + otherSheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, otherExtSheetIx);