Bug 14823 - Removing sheets in document with macro corrupts file
Summary: Removing sheets in document with macro corrupts file
Status: RESOLVED LATER
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: PC All
: P3 major with 1 vote (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-25 14:21 UTC by Marcin Nowak
Modified: 2008-08-05 15:56 UTC (History)
0 users



Attachments
example input file created with excel97 (14.50 KB, application/octet-stream)
2002-11-25 14:23 UTC, Marcin Nowak
Details
output file created with sample program (14.50 KB, application/octet-stream)
2002-11-25 14:24 UTC, Marcin Nowak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin Nowak 2002-11-25 14:21:09 UTC
Removing sheets during rewriting of documents that contain macros seems to
corrupt those files.

Way to reproduce bug:
1) Create empty excel document,
2) Add this macro to 'ThisWorbook':
Private Sub Workbook_Open()
End Sub
3) Save file to input.xls,
4) Compile and run this code:

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

public class Test
{	
	public static void main(String[] args)
	{
		try {
			HSSFWorkbook workBook = new HSSFWorkbook(new POIFSFileSystem(new
FileInputStream("input.xls")),
                                    true);
			HSSFSheet sheet = workBook.createSheet("X");
			workBook.removeSheetAt(0);

			FileOutputStream fileOut = new FileOutputStream("output.xls", false);
			workBook.write(fileOut);
			fileOut.close();
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}
}
 
4) Open output.xls and turn macros on

When Excel executes macro in Workbook_Open() Sub procedure, it exits with system
error message.

Version of poi:  poi-1.8.0-dev-20020919 and poi-1.9.0-dev-20021122
Version of os/excel: windows98se/excel97, windows98se/excel2000,
windowsme/excel97, windowsme/excel2000 (all polish versions)
Doesn’t occur on: 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:
1) Cloning exiting sheet using cloneSheet() method solves problem until cloned
sheet is removed too.
2) Name of removed sheet steel exists in Visual Basic Editor in VBAProject tree
Comment 1 Marcin Nowak 2002-11-25 14:23:51 UTC
Created attachment 3947 [details]
example input file created with excel97
Comment 2 Marcin Nowak 2002-11-25 14:24:52 UTC
Created attachment 3948 [details]
output file created with sample program
Comment 3 Marcin Nowak 2002-11-25 14:28:34 UTC
ArkuszX where X=1,2,... is the default name of new sheet created in polish
version of Excel.
Comment 4 Andy Oliver 2003-07-24 13:50:40 UTC
I think I know whats happening...However it will require some structural
changes.  Best do it in 3.0
Comment 5 Marcos Arante 2004-11-04 15:55:59 UTC
someone know when we'll have this bug solved ?
Comment 6 Yegor Kozlov 2008-05-17 06:49:58 UTC
Please check if the problem still exists in 3.1-beta1.

Yegor
Comment 7 Nick Burch 2008-08-05 15:56:25 UTC
Guessing this is now fixed. Please re-open the bug if it still occurs on re-testing with a recent version (eg 3.1)