原創(chuàng)|使用教程|編輯:鄭恭琳|2019-10-30 14:46:49.130|閱讀 422 次
概述:本示例說明在查看器中打印或?qū)С鰣?bào)表之前如何執(zhí)行所需的操作。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
立即點(diǎn)擊下載Stimulsoft Reports.Net最新版
本示例說明在查看器中打印或?qū)С鰣?bào)表之前如何執(zhí)行所需的操作。
首先您需要將StiMvcViewer組件添加到視圖頁面。您還需要將StiMvcViewerOptions對(duì)象傳遞給構(gòu)造函數(shù)。在選項(xiàng)中,您應(yīng)該設(shè)置以下操作:GetReport、PrintReport、ExportReport和ViewerEvent。在報(bào)表打印和導(dǎo)出時(shí)將相應(yīng)調(diào)用最后兩個(gè)操作。
@using Stimulsoft.Report.Mvc; ... @Html.Stimulsoft().StiMvcViewer(new StiMvcViewerOptions() { Actions = { GetReport = "GetReport", PrintReport = "PrintReport", ExportReport = "ExportReport", ViewerEvent = "ViewerEvent" } })
在上面的選項(xiàng)中,我們定義了幾個(gè)動(dòng)作,我們需要將其添加到控制器中。
GetReport操作將加載報(bào)表并使用GetReportResult()靜態(tài)方法將答案返回給查看器的客戶端。在此方法的參數(shù)中,應(yīng)傳遞報(bào)表對(duì)象。
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()靜態(tài)方法將答案返回給客戶端。
public ActionResult ViewerEvent() { return StiMvcViewer.ViewerEventResult(); }
通過查看器菜單打印報(bào)表時(shí),將調(diào)用PrintReport操作。在此操作中,您可以獲取報(bào)表對(duì)象并執(zhí)行任何操作,例如連接到數(shù)據(jù)。要為客戶準(zhǔn)備答案,您應(yīng)該使用PrintReportResult()靜態(tài)方法。
public ActionResult PrintReport() { StiReport report = StiMvcViewer.GetReportObject(); // Some actions with report when printing return StiMvcViewer.PrintReportResult(report); }
通過查看器菜單以任何格式導(dǎo)出報(bào)表時(shí),將調(diào)用ExportEvent操作。您可以獲取報(bào)表對(duì)象并執(zhí)行任何操作。您還可以獲取查看器的操作參數(shù),例如,在PDF報(bào)表導(dǎo)出時(shí)執(zhí)行一些操作。要為客戶準(zhǔn)備答案,您應(yīng)該使用ExportReportResult()靜態(tài)方法。
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); }
在下面的屏幕截圖中,您可以看到示例代碼的結(jié)果。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn