Stimulsoft ASP.NET MVC报表教程:管理报表打印和导出

本示例说明在查看器中打印或导出报表之前如何执行所需的操作。

本示例说明在查看器中打印或导出报表之前如何执行所需的操作。

首先您需要将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);}

在下面的屏幕截图中,您可以看到示例代码的结果。

Stimulsoft ASP.NET MVC报表教程:管理报表打印和导出

下载示例代码

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年9月27日
下一篇 2019年9月27日

相关推荐

发表回复

登录后才能评论