Home
Analytics
Integrating Birt 2.5.1 with Apache POI ??
kiranv
I want to integrate my Birt report with Apache POI. Like after generating report in the desired format (doc/ppt/xls) i want to further manipulate and modify the report runtime for the particular format.
So say i render report as XLS then i would want to have access to the excel sheet or if it is a PPT then to the particular slide.
Has anyone done something like this???
Here is an example of what i want exactly.
My working source code to generate the report is-
ByteArrayOutputStream reportOutput = new ByteArrayOutputStream();
IReportEngine birtReportEngine = BirtEngine.getBirtEngine();
IReportRunnable design = null;
String reportPath==getContext().getServletContext().getRealPath("/reports")+ "/reportchart.rptdesign";
design = birtReportEngine.openReportDesign(reportPath);
IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design);
IRenderOption options = new RenderOption();
options.setOutputFormat(outputFormat);//outputFormat="xls","ppt","doc"
options.setOutputStream(reportOutput);
Map appContext = task.getAppContext();
appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,
GenerateReportActionBean.class.getClassLoader());
task.setAppContext(appContext);
task.setRenderOption(options);
task.run();
task.close();
Now the reportOutput object has the report in the desired format. Say i know it is an excel file.
So i want to access the sheet at runtime with something like
HSSFWorkbook wb = new HSSFWorkbook(); //Apache POI classes
wb.write(reportOutput);
now i can access the sheet/row/column/cell of the report by say
Sheet sheet= wb.getSheet(0) ..or something like this..
Has anyone integrated Apache POI with BIRT 2.5.1.
If yes, then any kind of help is really appreciated.
Find more posts tagged with
Comments
kiranv
Got it working..
here is the code.
Define an output folder say in the temp. directory of ur local HDD-
String outputFolderPath="C:/temp/output/WebReport.xls";
For a web application you can create a folder WEB-INF and then access it from servlet context.
Assume the generated report is in xls format-
//Save the xls file in the output folder
OutputStream outputStream = new FileOutputStream (outputFolderPath);
reportOutput.writeTo(outputStream);
HSSFWorkbook wb=new HSSFWorkbook( new FileInputStream(outputFolderPath));
Now u have access to the generated workbook.
U can manipulate the workbook using all Apache POI APIs like say
wb.setSheetName(0, "Hierarchy");
Finally again store the xls in a ByteArrayOutPutStream
reportOutput = new ByteArrayOutputStream();
wb.write(reportOutput);
Thats it done..
Similarly u can access a DOC/PPT report generated from Birt in a J2EE web application
kiranv
It will only work with Tribix Emitters <a class='bbc_url' href='
https://sourceforge.net/projects/tribix/'>https://sourceforge.net/projects/tribix/</a><br
/>
<br />
else it might give an error something like this - <br />
"Invalid header signature; read 7888090397404325948,<br />
expected -2226271756974174256"<br />
<br />
The reason being the excel file generated by BIRT is in Binary format. <br />
<br />
I am working on this solution and if solved, will post the solution for it.
QBiT
Hi kiranv,<br />
<br />
seems that you have a similar problem like me. See:<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/forum/deploying-integrating-birt-report-engine-applications/18675-ppt-poi-issue.html'>http://www.birt-exchange.org/forum/deploying-integrating-birt-report-engine-applications/18675-ppt-poi-issue.html</a><br
/>
<br />
Since i just try to merge multiple ppt files which where generated from different design files using the build in BIRT PPTWriter, i am currently trying to extend the BIRT PPT Emitter to have a like merge functionality.
kiranv
Working code for integrating apache poi with birt 2.5.1
Assuming the variable reportOutput which is an object of ByteArrayOutputStream contains report data. now do something like this
byte[] inputBytes = reportOutput.toByteArray();
reportOutput = new ByteArrayOutputStream();
HSSFWorkbook wb = new HSSFWorkbook(new ByteArrayInputStream(
inputBytes));
setWorkbookProperties(wb);
wb.write(reportOutput);
In a private method private void setWorkbookProperties(HSSFWorkbook wb) {} u can modify properties of workbook using apache POI
Abhinandna
Hi Kinav,
Can you provide the solution in more detail, I am still getting Invalid header signature.
Please help.
Abhinandan