原創|使用教程|編輯:鄭恭琳|2019-10-30 14:46:49.130|閱讀 422 次
概述:本示例說明在查看器中打印或導出報表之前如何執行所需的操作。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
立即點擊下載Stimulsoft Reports.Net最新版
本示例說明在查看器中打印或導出報表之前如何執行所需的操作。
首先您需要將StiMvcViewer組件添加到視圖頁面。您還需要將StiMvcViewerOptions對象傳遞給構造函數。在選項中,您應該設置以下操作:GetReport、PrintReport、ExportReport和ViewerEvent。在報表打印和導出時將相應調用最后兩個操作。
@using Stimulsoft.Report.Mvc; ... @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", PrintReport = "PrintReport", ExportReport = "ExportReport", ViewerEvent = "ViewerEvent" } })
在上面的選項中,我們定義了幾個動作,我們需要將其添加到控制器中。
GetReport操作將加載報表并使用GetReportResult()靜態方法將答案返回給查看器的客戶端。在此方法的參數中,應傳遞報表對象。
public ActionResult GetReport() { // Create the report object StiReport report = new StiReport(); report.Load(Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt")); // Load data from XML file for report template DataSet data = new DataSet("Demo"); data.ReadXml(Server.MapPath("~/Content/Data/Demo.xml")); report.RegData(data); return StiMvcViewer.GetReportResult(report); }
ViewerEvent操作處理所有查看器事件(切換頁面、縮放等),并使用ViewerEventResult()靜態方法將答案返回給客戶端。
public ActionResult ViewerEvent() { return StiMvcViewer.ViewerEventResult(); }
通過查看器菜單打印報表時,將調用PrintReport操作。在此操作中,您可以獲取報表對象并執行任何操作,例如連接到數據。要為客戶準備答案,您應該使用PrintReportResult()靜態方法。
public ActionResult PrintReport() { StiReport report = StiMvcViewer.GetReportObject(); // Some actions with report when printing return StiMvcViewer.PrintReportResult(report); }
通過查看器菜單以任何格式導出報表時,將調用ExportEvent操作。您可以獲取報表對象并執行任何操作。您還可以獲取查看器的操作參數,例如,在PDF報表導出時執行一些操作。要為客戶準備答案,您應該使用ExportReportResult()靜態方法。
public ActionResult ExportReport() { StiReport report = StiMvcViewer.GetReportObject(); StiRequestParams parameters = StiMvcViewer.GetRequestParams(); if (parameters.ExportFormat == StiExportFormat.Pdf) { // Some actions with report when exporting to PDF } return StiMvcViewer.ExportReportResult(report); }
在下面的屏幕截圖中,您可以看到示例代碼的結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn