Bug 14824 - Unable to modify empty sheets
Summary: Unable to modify empty sheets
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-dev
Hardware: PC All
: P3 normal with 2 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
: 21278 (view as bug list)
Depends on:
Reported: 2002-11-25 14:47 UTC by Marcin Nowak
Modified: 2004-11-16 19:05 UTC (History)
2 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Nowak 2002-11-25 14:47:31 UTC
Rewriting empty sheets using poi doesn't produce almost any effect on modified
sheet. It means there are no values inserted, no styles applied to cells. Only
thing I can actually see in Excel are merged regions, and it means worksheet is
being really modified.
Way to reproduce:
1) Create empty Excel document (don't change anything),
2) Save to input.xls,
3) Compile and run this code:

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hssf.util.*;
import java.io.*;

public class Test2
	public static void main(String[] args)
		try {
			HSSFWorkbook workBook = new HSSFWorkbook(new POIFSFileSystem(new
FileInputStream("input.xls")), true);
			HSSFSheet sheet = workBook.getSheetAt(0);
			HSSFRow row = sheet.createRow((short) 0);
			if (row == null)
				row = sheet.createRow((short) 0);
			HSSFCell tmpCell = row.getCell((short) 0);
			if (tmpCell == null)
				tmpCell = row.createCell((short)0);


			sheet.addMergedRegion(new Region(1, (short) 0, 1, (short) 1));

			FileOutputStream fileOut = new FileOutputStream("output.xls", false);
		catch (Exception ex){

3) Open output.xls

You see empty sheet (without 'XYZ' string in cell(0,0)) with one merged region.

Version of poi:  poi-1.9.0-dev-20021122
Version of os/excel: windows2000prof/excel2002 (polish version)
Version of jdk: sun jdk 1.3.1
Compile command: javac -classpath ".\jakarta-poi-1.9.0-dev-20021122.jar"
Execution command: java -classpath ".;.\jakarta-poi-1.9.0-dev-20021122.jar"

Additional information:
There is simple workaround for this problem. Modify sheet in Excel putting (for
example) one space into cell(0,0).
Comment 1 Tim Schafer 2003-07-18 19:19:17 UTC
I have seen the behavior of only merged cells, but no other changes
showing up in result.

However starting with a modified spreadsheet doesn't work.
My original template (some text, and a graphic) has the same problem.

It's only because I wanted a simple test case that I tried 
it with a blank sheet.

see bug 21066
Comment 2 Andy Oliver 2003-07-24 17:01:12 UTC
*** Bug 21278 has been marked as a duplicate of this bug. ***
Comment 3 Glen Stampoultzis 2003-09-21 11:20:34 UTC
I just committed something that may possibly fix your problem.  You can get a
jar from: http://www.apache.org/~glens/poi-20030921.jar
Comment 4 Marcin Nowak 2003-09-23 06:32:36 UTC
Confirming that your fix resolves the problem. However I haven't tested it with
more complex example, only with code listed above.
Additional note: output file is slightly smaller then input file (13312 bytes
comparing with original 13824 bytes).
Comment 5 Glen Stampoultzis 2003-10-08 08:34:24 UTC
If you find any further problems please reopen this bug.