Bug 47041 - Getting error while creating a worksheet using XSSFWorkbook class
Summary: Getting error while creating a worksheet using XSSFWorkbook class
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL: http://www.nabble.com/Getting-error-w...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-16 22:43 UTC by Naveen
Modified: 2009-04-17 09:47 UTC (History)
1 user (show)



Attachments
test files (24.65 KB, application/zip)
2009-04-16 22:43 UTC, Naveen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Naveen 2009-04-16 22:43:45 UTC
Created attachment 23502 [details]
test files

Hi,

I am getting the following run time excception while crting a worksheet using XSSFWorkbook class: 

I have written the 2 test cases to create the same error.t I am using removesheetAt(0) method of Workbook Interface (SS Model).

I am doing the same testing with HSSFWorkbook, and this is working as per my requirment.

But same test case is not working with XSSFWorkbook. I have attached the test code please have a look of this error.

1>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Test Case - FAIL
public void testImportMacroXLSM() throws Exception {
                  String filename = "C:\\poi-src-3.5-beta5-20090219\\poi-3.5-beta5\\test.xlsm";
                  InputStream macro = new FileInputStream(filename);
                    String file = "test1.xlsm";
                  //POIFSFileSystem poiFileStream = new POIFSFileSystem(macro);
                  Workbook _workBook = new XSSFWorkbook(Package.open(macro));
                  _workBook.removeSheetAt(0);
                  _workBook.createSheet("1. test2").createRow(1).createCell(1).setCellValue("test");
                    FileOutputStream out = new FileOutputStream("c:/"+file);
                    _workBook.write(out);
                         out.close();
                 
                 }
2>>>>>>>>>>>>>>>>>>>>>>>>>>Test Case - PASS
                 public void testImportMacroXLS() throws Exception {
                  String filename = "C:\\poi-src-3.5-beta5-20090219\\poi-3.5-beta5\\test.xls";
                  InputStream macro = new FileInputStream(filename);
                    String file = "test1.xls";
                  //POIFSFileSystem poiFileStream = new POIFSFileSystem(macro);
                  Workbook _workBook = new HSSFWorkbook(macro);
                  _workBook.removeSheetAt(0);
                  _workBook.createSheet("1. test2").createRow(1).createCell(1).setCellValue("test");
                    FileOutputStream out = new FileOutputStream("c:/"+file);
                    _workBook.write(out);
                         out.close();
                 
                 }
3>>>>>>>>>>>>>>>>Test case - FAIL


        public void testImportMacroXLSM() throws Exception {
                String filename = "C:\\poi-src-3.5-beta5-20090219\\poi-3.5-beta5\\test.xlsx";
                InputStream macro = new FileInputStream(filename);
                  String file = "test1.xlsx";
                //POIFSFileSystem poiFileStream = new POIFSFileSystem(macro);
                Workbook _workBook = new XSSFWorkbook(Package.open(macro));
                _workBook.removeSheetAt(0);
                _workBook.createSheet("1. test2").createRow(1).createCell(1).setCellValue("test");
                  FileOutputStream out = new FileOutputStream("c:/"+file);
                  _workBook.write(out);
                out.close();
                       
        } 

On running the 1st and 3rd test case I am getting the following exception :

=======================

org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidOperationException: A part with the name '/xl/worksheets/sheet1.xml' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
                 at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:216)
                 at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:189)
                 at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:467)
                 at org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet(XSSFWorkbook.java:1)
                 at org.apache.poi.hssf.extractor.TestExcelExtractor.testImportMacro(TestExcelExtractor.java:254)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                 at java.lang.reflect.Method.invoke(Unknown Source)
                 at junit.framework.TestCase.runTest(TestCase.java:154)
                 at junit.framework.TestCase.runBare(TestCase.java:127)
                 at junit.framework.TestResult$1.protect(TestResult.java:106)
                 at junit.framework.TestResult.runProtected(TestResult.java:124)
                 at junit.framework.TestResult.run(TestResult.java:109)
                 at junit.framework.TestCase.run(TestCase.java:118)
                 at junit.framework.TestSuite.runTest(TestSuite.java:208)
                 at junit.framework.TestSuite.run(TestSuite.java:203)
                 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
                 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidOperationException: A part with the name '/xl/worksheets/sheet1.xml' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]
                 at org.apache.poi.openxml4j.opc.Package.createPart(Package.java:692)
                 at org.apache.poi.openxml4j.opc.Package.createPart(Package.java:656)
                 at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:208)
                 ... 22 more


=============================test.zip

I have written the test case in TestExcelExtractor.java file. and I am using the latest jar files which i have downloaded from http://encore.torchbox.com/poi-svn-build/

One More thing to add:

Both the input workbook must contain only one sheet.

Please add the test cases in  TestExcelExtractor.java and test again.

Please let me know if anything else is required.

Regards
Naveen
Comment 1 Yegor Kozlov 2009-04-17 09:47:55 UTC
Your sample code works fin with the latest trunk.
Check the classpath. You seems to be using an old version of POI. 

See what the following statement prints:        
System.out.println(XSSFWorkbook.class.getClassLoader().getResource("org/apache/poi/xssf/usermodel/XSSFWorkbook.class"));

Yegor