翻譯|使用教程|編輯:王香|2018-10-22 09:54:34.000|閱讀 717 次
概述:此示例項(xiàng)目顯示如何在不使用報(bào)表查看器的情況下從代碼打印報(bào)表。對(duì)于此操作,只需使用實(shí)現(xiàn)報(bào)表打印方法的特殊StiReportResponse類即可。這些方法接受所有必要參數(shù)的輸入以配置導(dǎo)出和打印報(bào)表。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
特殊的StiReportResponse類包含兩種報(bào)表打印模式:打印為PDF并以HTML 格式打印。例如,為一個(gè)報(bào)表實(shí)現(xiàn)這些模式以便比較它們。為每種打印模式添加兩個(gè)按鈕,并為這些按鈕添加單擊事件處理程序。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Print_Report_from_Code.Default" %> <!DOCTYPE html> <html xmlns="//www.w3.org/1999/xhtml"> <head runat="server"> <title>Print and Export Report from Code</title> </head> <body> <form id="form1" runat="server"> <br /><br /> <asp:Button ID="ButtonPrintPDF" runat="server" Text="Print Report as PDF" OnClick="ButtonPrintPdf_Click" /> <br /><br /> <asp:Button ID="ButtonPrintHTML" runat="server" Text="Print Report as HTML" OnClick="ButtonPrintHtml_Click" /> <br /><br /> </form> </body> </html>
在ButtonPrintPdf_Click事件中,它獲取報(bào)表并調(diào)用StiReportResponse類的PrintAsPdf()靜態(tài)方法。報(bào)表將自動(dòng)生成,導(dǎo)出為PDF并發(fā)送打印 - 將顯示系統(tǒng)打印對(duì)話框。
protected void ButtonPrintPdf_Click(object sender, EventArgs e) { StiReport report = this.GetReport(); StiReportResponse.PrintAsPdf(report); }
在ButtonPrintHtml_Click事件中,它獲取報(bào)表并調(diào)用StiReportResponse類的PrintAsHtml()靜態(tài)方法。報(bào)表將自動(dòng)生成,導(dǎo)出為HTML并發(fā)送以進(jìn)行打印 - 將顯示系統(tǒng)打印對(duì)話框。
protected void ButtonPrintHtml_Click(object sender, EventArgs e) { StiReport report = this.GetReport(); StiReportResponse.PrintAsHtml(report); }
要獲取報(bào)表,使用了GetReport()方法。此方法加載報(bào)表模板,加載XML數(shù)據(jù)文件并為加載的報(bào)表注冊(cè)此數(shù)據(jù)。
private StiReport GetReport() { string reportPath = Server.MapPath("Reports/SimpleList.mrt"); StiReport report = new StiReport(); report.Load(reportPath); string dataPath = Server.MapPath("Data/Demo.xml"); DataSet data = new DataSet(); data.ReadXml(dataPath); report.RegData(data); return report; }
示例代碼的結(jié)果如下圖所示:
購買Stimulsoft正版授權(quán),請(qǐng)點(diǎn)擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn