範例一:匯出報表

以下範例是一個簡單的 JSP 頁面,示範如何使用匯出控制項將報表的前三頁匯出為 RTF。

注意:    本範例所使用的報表不包含在教學課程中。

exportreport.jsp

<%@ page import="com.crystaldecisions.report.web.viewer.ReportExportControl" %>

<%@ page import="com.crystaldecisions.reports.sdk.ReportClientDocument" %>

<%@ 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.exportoptions.RTFWordExportFormatOptions" %>

<%

    Object reportSource = session.getAttribute("reportSource");

    if (reportSource == null)

    {

       String report = "/reports/sample.rpt";

       ReportClientDocument reportClientDoc = new ReportClientDocument();

       reportClientDoc.open(report, 0);

       reportSource = reportClientDoc.getReportSource();

       session.setAttribute("reportSource", reportSource);

    }

    ReportExportControl exportControl = new ReportExportControl();

    ExportOptions exportOptions = new ExportOptions();

    exportOptions.setExportFormatType(ReportExportFormat.RTF);

    RTFWordExportFormatOptions RTFExpOpts = new RTFWordExportFormatOptions();

    RTFExpOpts.setStartPageNumber(1);

    RTFExpOpts.setEndPageNumber(3);

    exportOptions.setFormatOptions(RTFExpOpts);    

    exportControl.setReportSource(reportSource);

    exportControl.setExportOptions(exportOptions);

    exportControl.setExportAsAttachment(true);

    exportControl.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

%>



Business Objects
http://www.taiwan.businessobjects.com/
支援服務
http://www.businessobjects.com/services/support/