poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "A. Rick Anderson" <a_r...@earthlink.net>
Subject Can't append a new cell to existing row
Date Fri, 17 Nov 2006 04:06:01 GMT
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/


Mime
View raw message