原創|使用教程|編輯:鄭恭琳|2019-10-30 14:18:58.587|閱讀 355 次
概述:此示例項目說明了如何在不使用報表查看器的情況下從代碼導出和打印報表。為此,使用特殊的StiReportResponse類足以實現報表導出和打印的方法。這些方法輸入所有必需的參數,以配置導出和打印報表。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
立即點擊下載Stimulsoft Reports.Net最新版
此示例項目說明了如何在不使用報表查看器的情況下從代碼導出和打印報表。為此,使用特殊的StiReportResponse類足以實現報表導出和打印的方法。這些方法輸入所有必需的參數,以配置導出和打印報表。
特殊的StiReportResponse類包含用于導出任何格式的報表并將報表打印為PDF和HTML的方法。例如,為一個報表實施它以進行比較。為每種打印模式添加兩個鏈接,為各種導出格式添加三個鏈接。
<div class="row"> <div class="col-md-4"> <h2>Print to PDF</h2> <p>@Html.ActionLink("Print", "PrintPdf")</p> </div> <div class="col-md-4"> <h2>Print to HTML</h2> <p>@Html.ActionLink("Print", "PrintHtml")</p> </div> </div> <hr /> <div class="row"> <div class="col-md-4"> <h2>Export to PDF</h2> <p>@Html.ActionLink("Export", "ExportPdf")</p> </div> <div class="col-md-4"> <h2>Export to HTML</h2> <p>@Html.ActionLink("Export", "ExportHtml")</p> </div> <div class="col-md-4"> <h2>Export to Excel</h2> <p>@Html.ActionLink("Export", "ExportXls")</p> </div> </div>
為了獲取報表,使用了GetReport()方法。此方法加載報表模板、加載XML數據文件,并為加載的報表注冊此數據。
private StiReport GetReport() { string reportPath = Server.MapPath("~/Content/Reports/TwoSimpleLists.mrt"); var report = new StiReport(); report.Load(reportPath); string dataPath = Server.MapPath("~/Content/Data/Demo.xml"); var data = new DataSet("Demo"); data.ReadXml(dataPath); report.RegData(data); return report; }
現在,我們需要確定單擊鏈接時將調用的操作。對于打印,我們將使用兩種操作方法——PrintPdf和PrintHtml。
public ActionResult PrintPdf() { StiReport report = this.GetReport(); StiReportResponse.PrintAsPdf(report); return View(); } public ActionResult PrintHtml() { StiReport report = this.GetReport(); StiReportResponse.PrintAsHtml(report); return View(); }
對于打印,我們將使用三種操作方法——ExportPdf、ExportHtml和ExportXls。以這些導出格式為例。同樣,導出報表(和打印)的方法可以將導出設置和其他必要參數作為輸入。
public ActionResult ExportPdf() { StiReport report = this.GetReport(); StiReportResponse.ResponseAsPdf(report); return View(); } public ActionResult ExportHtml() { StiReport report = this.GetReport(); StiReportResponse.ResponseAsHtml(report); return View(); } public ActionResult ExportXls() { StiReport report = this.GetReport(); StiReportResponse.ResponseAsXls(report); return View(); }
在下面的屏幕截圖中,您可以看到示例代碼的結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn