You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Kyle.Bober" <ky...@gmail.com> on 2009/06/08 18:08:17 UTC

Opening BIRT Excel Report using Apache POI

Hi all,
  I have created and Excel report using Eclipse BIRT 2.3.2 and now I want to
open up the BIRT Excel file in Apache POI. It seems the format of the Excel
BIRT Report is in XML and when I try to open it up using the following code
I receive the following exception?

FileInputStream fileInputStream =  new FileInputStream(aFile);		
POIFSFileSystem poiFileSystem = new POIFSFileSystem(fileInputStream);
HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem);	

java.io.IOException: Invalid header signature; read 7311066695147732796,
expected -2226271756974174256
	at
org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:112)
	at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
	at
com.thesearchagency.util.poi.POIManager.openExcelWorkbook(POIManager.java:17)
	at
com.thesearchagency.util.birt.BIRTManagerTest.mergeWorksheets(BIRTManagerTest.java:107)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	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)


My overall objective is to copy multiple worksheets from various BIRT Excel
Reports and then merge them into one master Excel Workbook. If anyone has
any advice regarding this I would appreciate it.

-Kyle


-- 
View this message in context: http://www.nabble.com/Opening-BIRT-Excel-Report-using-Apache-POI-tp23927052p23927052.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Opening BIRT Excel Report using Apache POI

Posted by MSB <ma...@tiscali.co.uk>.
Hello Kyle,

The first thing to say is that if the report is indeed in OpenXML format,
then you need to use the XSSF stream and not the HSSF stream. To use XSSF
you must have the current version of POI - that is 3.5 and not 3.2 final.

Firstly though, check that you do have an OpenXML file as there is more than
one Excel xml format. Try to open the file using something like winzip or
winrar. OpenXML files are zipped archives and can be opened using such a
tool; the archive ought to contain directories called something like
'_rels', 'docProps' and 'xl'. If the file opens successfully with a zip
utility and you see a listing with those directories mentioned then you need
to use the XSSF stream to process the file. In many ways the code you have
found for the HSSF stream can be simply converted for use with an OpenXML
file;

// Replace the words Your File with the name of the file
// to be processed.
XSSFWorkbook workbook = new XSSFWorkbook("Your File");
XSSFSheet = null;
XSSFRow row = null;
XSSFCell cell = null;
Iterator<Row> rowIterator = null;
Iterator<Cell> cellIterator = null;
int numSheets = workbook.getNumberOfSheets();
for(int i = 0; i < numSheets; i++) {
     XSSFSheet = workbook.getSheetAt(i);
     rowIterator = sheet.rowIterator();
     while(rowIterator.hasNext()) {
          row = rowIterator.next();
          cellIterator = row.cellIterator();
          while(cellIterator.hasNext()) {
               cell = cellIterator.next();
               System.out.println(cell);
          }
     }
}

This will simply work through the sheets in the workbook, the rows in each
sheet and the cells in each row. Of course, there is far more to using the
API than this but it should get you started.

If the file cannot be opened by a zip utility, then you may have an Office
2003 xml file. These can be read using a simple text editor like wordpad and
you should try opening the file that way just to confirm our suspicions;
sadly however they cannot be processed with POI. A few days ago, another
member of this list - newsletter-42 - suggested using xmlBeans
(http://xmlbeans.apache.org/) to process such a file. The difficulty I have
found with that is obtaining the DTD for the document from Microsoft; if you
can get the DTD then this is certainly the tool to use IMO.

All the best and let us know how you get on.

Yours

Mark B


Kyle.Bober wrote:
> 
> Hi all,
>   I have created and Excel report using Eclipse BIRT 2.3.2 and now I want
> to open up the BIRT Excel file in Apache POI. It seems the format of the
> Excel BIRT Report is in XML and when I try to open it up using the
> following code I receive the following exception?
> 
> FileInputStream fileInputStream =  new FileInputStream(aFile);		
> POIFSFileSystem poiFileSystem = new POIFSFileSystem(fileInputStream);
> HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem);	
> 
> java.io.IOException: Invalid header signature; read 7311066695147732796,
> expected -2226271756974174256
> 	at
> org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:112)
> 	at
> org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
> 	at
> com.thesearchagency.util.poi.POIManager.openExcelWorkbook(POIManager.java:17)
> 	at
> com.thesearchagency.util.birt.BIRTManagerTest.mergeWorksheets(BIRTManagerTest.java:107)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:585)
> 	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> 	at
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
> 	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> 	at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
> 	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> 	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> 	at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> 	at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> 	at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> 	at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> 	at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> 	at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> 	at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
> 	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)
> 
> 
> My overall objective is to copy multiple worksheets from various BIRT
> Excel Reports and then merge them into one master Excel Workbook. If
> anyone has any advice regarding this I would appreciate it.
> 
> -Kyle
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-BIRT-Excel-Report-using-Apache-POI-tp23927052p23928223.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org