https://issues.apache.org/bugzilla/show_bug.cgi?id=47041
Summary: Getting error while creating a worksheet using
XSSFWorkbook class
Product: POI
Version: 3.5-dev
Platform: PC
URL: http://www.nabble.com/Getting-error-while-creating-a-w
orksheet-using-XSSFWorkbook-class(APACHE-3.5-beta-4)-t
d22822952.html#a22822952
OS/Version: Windows XP
Status: NEW
Severity: critical
Priority: P2
Component: XSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
Created an attachment (id=23502)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=23502)
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
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]