匯出控制項處理報表匯出作業的各個層面,利用下載對話方塊提示使用者,選擇在瀏覽器視窗內預覽匯出的報表,或將報表以附件形式匯出。匯出控制項是以 ReportExportControl 類別來代表。
<%@ page import="com.crystaldecisions.report.web.viewer.ReportExportControl" %>
<%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>
<%@ 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" %>
ReportExportControl exportControl = new ReportExportControl();
一旦建立 ReportExportControl
物件後,就必須指定所要的匯出格式。在本範例中,我們已選擇 RTF 做為匯出格式。如需完整的匯出格式清單,請參閱匯出格式。
ExportOptions exportOptions = new ExportOptions();
exportOptions.setExportFormatType(ReportExportFormat.RTF);
注意 您可以在《Crystal Reports for Rational Application Developer Java API 參考》中的 ReportExportFormat 類別文件中,找到指定匯出格式的有效常數清單。
某些格式包含額外的選項,若加以設定可自訂匯出報表的方式。例如,您可以控制某些格式的匯出頁面範圍。
在這種情況下,因為匯出格式是 RTF,所以會建立 RTFWordExportFormatOptions 物件。
RTFWordExportFormatOptions RTFExpOpts = new RTFWordExportFormatOptions();
在本範例中,已經設定匯出選項,所以只會匯出第 1 到 3 頁。
RTFExpOpts.setStartPageNumber(1);
RTFExpOpts.setEndPageNumber(3);
exportControl.setReportSource(reportSource);
exportControl.setExportOptions(exportOptions);
將此方法設定為 True 會顯示對話方塊,讓您的 Web 應用程式使用者可以在開啟匯出的報表之前加以儲存,否則,如果瀏覽器可以開啟匯出的檔案類型,則匯出的報表會直接顯示在瀏覽器視窗內。
Business Objects http://www.china.businessobjects.com Support services http://www.china.businessobjects.com |