You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "A. Rick Anderson" <a_...@earthlink.net> on 2006/11/17 05:06:01 UTC

Can't append a new cell to existing row

I am trying to update an existing Excel file.  But the updates are not 
being saved.

When I append a new cell on the end of an existing row, and then save 
the workbook to a new file, the new file is identical to the old file.

The cell gets created.  I can see it in the debugger.  I can get it to 
print a value.  But when I write out the workbook out to a file, the new 
cell disappears.

I've been following the how-to guide on the site, and I traced down the 
HSSF.java code and reviewed the "main" method in there.  It looks like I 
am following the same code pattern.  According to the HSSF code, it 
doesn't look like I need to remove anything, if I am just adding new 
objects, such as an append.

This is how I'm writing out the file:

POIFSFileSystem fs = readExcelFile(file);
FileOutputStream os = new FileOutputStream(file + "new.xls");
fs.writeFilesystem(os);
os.close();

Here is the append code:

private void appendRateColumn(HSSFRow row) {
  int rowNumber = row.getRowNum();
  HSSFCell rateCell = row.createCell(RateColumn,
                                     HSSFCell.CELL_TYPE_NUMERIC);
  HSSFCell cellOfHoursWorked = row.getCell(SumOfQuantityColumn);
  HSSFCell cellOfAmount = row.getCell(SumOfAmountColumn);
  double hoursWorked = cellOfHoursWorked.getNumericCellValue();
  double amount = cellOfAmount.getNumericCellValue();
  rateCell.setCellValue(amount/hoursWorked);
  System.out.println("CELL [" + getCellStringValue(rateCell) + "]");
} // method appendRateColumn(HSSFRow

-- 
A. Rick Anderson


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/