Hi Yegor, 

I have written the 2 test cases to create the same error. sorry I have
missed to tell you that 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
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             
                 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();
                                                 
                 }

On running the 1st 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


============================= http://www.nabble.com/file/p22864106/test.zip
test.zip 

I have written the test case in TestExcelExtractor.java file.

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
-- 
View this message in context: 
http://www.nabble.com/Getting-error-while-creating-a-worksheet-using-XSSFWorkbook-class%28APACHE-3.5-beta-4%29-tp22822952p22864106.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to