I'm using POI to write rows/cells to a existing xls file that is completely empty. I generated the empty spreadsheet by creating a new excel file and saving the file.
When I run my POI code, it fails to insert any data.
However, when I try the same code with existing xls file that
has data, it inserts the data correctly.
Is this a bug? Attached is the blank spreadsheet i'm working with.
HSSF hssf = new HSSF("c:/blank.xls");
HSSFWorkbook wb = hssf.hssfworkbook;
FileOutputStream stream = new
FileOutputStream("c:/output.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow currRow = sheet.getRow(0);
//If current row is null in the spreadsheet
create a new row
if (currRow == null) {
currRow = sheet.createRow(0);
System.out.println("Creating new
row");
}
HSSFCell c = currRow.getCell((short)0);
if (c == null) {
HSSFCell newcell =
currRow.createCell((short)0);
newcell.setCellValue("test");
System.out.println("Creating new cell for
row");
}
else {
c.setCellValue("test");
}
wb.write(stream);
stream.close();
blank.xls
Description: MS-Excel spreadsheet
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
