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); tmpCell.setCellType(HSSFCell.CELL_TYPE_STRING); tmpCell.setCellValue("XYZ"); sheet.addMergedRegion(new Region(1, (short) 0, 1, (short) 1)); FileOutputStream fileOut = new FileOutputStream("output.xls", false); workBook.write(fileOut); fileOut.close(); } catch (Exception ex){ ex.printStackTrace(); } } } 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).
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
*** Bug 21278 has been marked as a duplicate of this bug. ***
I just committed something that may possibly fix your problem. You can get a jar from: http://www.apache.org/~glens/poi-20030921.jar
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).
If you find any further problems please reopen this bug.