Bug 21066 - Can not modify a blank spreadsheet
Summary: Can not modify a blank spreadsheet
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-pre3
Hardware: All All
: P3 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2003-06-24 21:57 UTC by Tim Schafer
Modified: 2004-11-16 19:05 UTC (History)
0 users

testPOI.java (1.07 KB, text/plain)
2003-06-24 22:02 UTC, Tim Schafer
Excel 2000 blank spreadsheet (13.50 KB, application/octet-stream)
2003-07-14 16:54 UTC, Tim Schafer
Excel 2002 blank spreadsheet (13.50 KB, application/octet-stream)
2003-07-14 16:55 UTC, Tim Schafer

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Schafer 2003-06-24 21:57:54 UTC
I have tried:

In each case using POI to modify a blank (open Excel press save) spreadsheet
created using each of:
Excel 2000 (9.0.2720)
Excel 2002 (10.2614.2625)
resulted in a blank spreadsheet

Using other input spreadsheets of varying complexity would result in a corrupt
output spreadsheet
But generally the result spreadsheet appeared as if it had not been modified

This problem does not occur using jakarta-poi-1.5.1-final-20020615.jar

Code sample:

import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class testPOI {
	public static void main(String[] args) throws java.io.IOException,
java.io.FileNotFoundException {
		// section 1
		POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("blank.xls"));
		HSSFWorkbook wb = new HSSFWorkbook(fs);
		HSSFSheet sheet = wb.getSheetAt(0);
		// section 2
		//HSSFWorkbook wb = new HSSFWorkbook();
		//HSSFSheet sheet = wb.createSheet("new sheet");
		HSSFRow row = sheet.getRow(2);
		if(row == null)
			row = sheet.createRow((short)2);
		HSSFCell cell = row.getCell((short)3);
		if(cell == null)
			cell = row.createCell((short)3);
		cell.setCellValue("a test");
		FileOutputStream fileOut = new FileOutputStream("output.xls");
Comment 1 Tim Schafer 2003-06-24 22:00:58 UTC
If however section 1 is commented out and section 2 is enabled
causing a new wb and sheet to be created the example works fine
with the newer versions of POI
Comment 2 Tim Schafer 2003-06-24 22:02:22 UTC
Created attachment 6961 [details]
Comment 3 Tim Schafer 2003-07-14 16:54:49 UTC
Created attachment 7283 [details]
Excel 2000 blank spreadsheet
Comment 4 Tim Schafer 2003-07-14 16:55:24 UTC
Created attachment 7284 [details]
Excel 2002 blank spreadsheet
Comment 5 Andy Oliver 2003-07-24 16:59:42 UTC
we need to fix this..  I think there is a dupe.
Comment 6 Tim Schafer 2003-07-30 18:47:22 UTC
This is still broken in poi-2.0-pre3-20030728.jar
Comment 7 Glen Stampoultzis 2003-09-21 11:19:03 UTC
There's a fix in CVS that I just commited that might solve your problem.  Try
out this jar: http://www.apache.org/~glens/poi-20030921.jar