Skip to Content

Quick blog this time.

Crystal Reports for Eclipse 2.0 Service Pack 1 was just released!

It now supports full Microsoft Excel export – not just data-only, but the report, including images, in Excel format!

Java Server Pages code page sample:

bq. java_crj12_web_export_excel.jsp – CR Java SDK to export to Excel<br /><textarea cols=”75″ rows=”10″><%@ page import=”com.crystaldecisions.report.web.viewer.CrystalReportViewer,
                 com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
                 com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,
                 com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat,
                 java.io.ByteArrayInputStream”
%>
<%

String reportPath;

ReportClientDocument reportClientDocument;

ByteArrayInputStream byteArrayInputStream;

byte[] byteArray;

int bytesRead;

reportPath = request.getParameter(“report_path”);

/*

  • Instantiate ReportClientDocument and specify the Java Print Engine as the report processor.

  • Open a rpt file and export to Excel.  Stream Excel back to web browser.

*/

reportClientDocument = new ReportClientDocument();

reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);

reportClientDocument.open(reportPath, OpenReportOptions._openAsReadOnly);

byteArrayInputStream = (ByteArrayInputStream) reportClientDocument

        .getPrintOutputController().export(ReportExportFormat.MSExcel);

response.reset();

response.setHeader(“Content-disposition”, “inline;filename=crreport.xls”);

response.setContentType(“application/excel”);

byteArray = new byte[1024];

while((bytesRead = byteArrayInputStream.read(byteArray)) != -1) {

     response.getOutputStream().write(byteArray, 0, bytesRead);     

}

response.getOutputStream().flush();

response.getOutputStream().close();

reportClientDocument.close();

%>

Have Fun!

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Rizza Lynn Ponce
    1) Boxes and lines doesn’t show in my exported Excel
    2) Quirk in pagination: I have a report that I exported to PDF (2 pages) and to Excel. When I exported it to Excel, the page footer for the first page didn’t appear, only for the second page and no page break was inserted between the first page and the second page. Should be okay, since it seems that it treats the whole report as a single page. But the page footer that appeared for the 2nd page displays “Page 2 of 2” and there lies the problem.
    (0) 

Leave a Reply