Print Page | Close Window

Exporting Crystal 10 rpt file to Excel from jsp pa

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6520
Printed Date: 06 May 2024 at 2:53pm


Topic: Exporting Crystal 10 rpt file to Excel from jsp pa
Posted By: jfarzaneh
Subject: Exporting Crystal 10 rpt file to Excel from jsp pa
Date Posted: 29 May 2009 at 9:47pm

hi
I have problim by exporing rpt file to excel . The jsp page code is :


********************************************************************************************************************************************************

<%@ page contentType="application/vnd.ms-excel; charset=UTF-8" %>

<%@ page import="com.crystaldecisions.report.web.viewer.ReportExportControl" %>
<%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.definition.AreaSectionKind" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.exportoptions.ExcelExportFormatOptions" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.lib.ReportSDKException" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSource" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>

<%
    String report = "WSR.rpt";
    IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();
    IReportSource reportSource = null;
    try
    {
        reportSource = (IReportSource) rptSrcFactory.createReportSource(report, request.getLocale());
    }
    catch (ReportSDKException e)
    {
        e.printStackTrace();
    }

    String selectedFormat = "2";

    ReportExportControl exportControl = new ReportExportControl();
    ExportOptions exportOptions = new ExportOptions();

    if (selectedFormat.equals("0")/*Crystal Report*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.crystalReports);
    }
    else if (selectedFormat.equals("1")/*Word*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.MSWord);
    }
    else if (selectedFormat.equals("2")/*Excel*/)
    {
        ExcelExportFormatOptions excelOptions = new ExcelExportFormatOptions();
        excelOptions.setMaintainRelativeObjectPosition(true);
        excelOptions.setBaseAreaType(AreaSectionKind.detail);
        excelOptions.setConstantColWidth(10);
        excelOptions.setExcelTabHasColumnHeadings(true);
        excelOptions.setMaintainRelativeObjectPosition(true);
        excelOptions.setShowGridlines(true);
        excelOptions.setUseConstantColWidth(true);
        exportOptions.setFormatOptions(excelOptions);
        exportOptions.setExportFormatType(ReportExportFormat.MSExcel);
    }
    else if (selectedFormat.equals("3")/*Rich Text Format*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.RTF);
    }
    else if (selectedFormat.equals("5")/*PDF*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.PDF);
    }
    else if (selectedFormat.equals("6")/*Excel without formatting*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.recordToMSExcel);
    }
    else if (selectedFormat.equals("7")/*Text*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.text);
    }
    else if (selectedFormat.equals("8")/*CSV*/)
    {
        exportOptions.setExportFormatType(ReportExportFormat.characterSeparatedValues);
    }
    exportControl.setOwnPage(true);
    exportControl.setOwnForm(true);
    try
    {
        exportControl.setReportSource(reportSource);
    }
    catch (ReportSDKExceptionBase reportSDKExceptionBase)
    {
        reportSDKExceptionBase.printStackTrace();
    }


    exportControl.setExportOptions(exportOptions);
    exportControl.setExportAsAttachment(true);

    try
    {
//exportControl.processHttpRequest(request, response, application, null);
//exportControl.processHttpRequest(request, response, getServletConfig.().getServletContext(), null);

        exportControl.getHtmlContent(request, response, getServletConfig().getServletContext());
    }
    catch (ReportSDKExceptionBase reportSDKExceptionBase)
    {
        reportSDKExceptionBase.printStackTrace();
    }

    exportControl.dispose();
%>

********************************************************************************************************************************************************

I use apache tomcat 6.0.13 as web server and Crystal report 10 Java Reportnig Component and the jar files are :


********************************************************************************************************************************************************

CrystalCharting.jar
CrystalCommon.jar
CrystalExporting.jar
CrystalFCM.jar
CrystalFormulas.jar
CrystalQueryEngine.jar
CrystalReportEngine.jar
keycodeDecoder.jar
MetafileRenderer.jar
rasapp.jar
rascore.jar
rpoifs.jar
Serialization.jar
URIUtil.jar
webreporting-core.jar
webreportingtags.jar
xercesImpl.jar
Concurrent.jar
icu4j.jar
log4j.jar
xercesImpl.jar
xmlParserAPIs.jar

********************************************************************************************************************************************************

AND my CrystalReportEngine-confige.xml content is :

********************************************************************************************************************************************************

<?xml version="1.0" encoding="utf-8"?>
<CrystalReportEngine-configuration>
    <reportlocation>../reports/</reportlocation>
    <timeout>10</timeout>
<keycode>XXXXX-XXXXX-XXXXX</keycode></CrystalReportEngine-configuration>

********************************************************************************************************************************************************

AND my web.xml is :

********************************************************************************************************************************************************

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=" http://java.sun.com/xml/ns/javaee - http://java.sun.com/xml/ns/javaee "
         xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance - http://www.w3.org/2001/XMLSchema-instance "
         xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee - http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd - http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
         version="2.5">
    <context-param>
        <param-name>crystal_image_uri</param-name>
        <param-value>crystalreportviewers10</param-value>
    </context-param>
</web-app>

********************************************************************************************************************************************************

anyway,    
When I run the project for exporting the report to pdf or word, there is no problem. But whern i export the report to excel following exception is displayed :

com.crystaldecisions.report.web.viewer.ReportExportControl
Invalid post back event : {0}

I search for solving this problem, but i could not find any way to solve that.Confused

pls help me , if anyone know what is the problem and how to solve that !!!!

my email : mailto:jfarzaneh@gmail.com - jfarzaneh@gmail.com




Print Page | Close Window