翻譯|使用教程|編輯:王香|2018-10-22 09:54:34.000|閱讀 734 次
概述:此示例項目顯示如何在不使用報表查看器的情況下從代碼打印報表。對于此操作,只需使用實現(xiàn)報表打印方法的特殊StiReportResponse類即可。這些方法接受所有必要參數(shù)的輸入以配置導(dǎo)出和打印報表。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
特殊的StiReportResponse類包含兩種報表打印模式:打印為PDF并以HTML 格式打印。例如,為一個報表實現(xiàn)這些模式以便比較它們。為每種打印模式添加兩個按鈕,并為這些按鈕添加單擊事件處理程序。
<%@ 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事件中,它獲取報表并調(diào)用StiReportResponse類的PrintAsPdf()靜態(tài)方法。報表將自動生成,導(dǎo)出為PDF并發(fā)送打印 - 將顯示系統(tǒng)打印對話框。
protected void ButtonPrintPdf_Click(object sender, EventArgs e)
{
StiReport report = this.GetReport();
StiReportResponse.PrintAsPdf(report);
}
在ButtonPrintHtml_Click事件中,它獲取報表并調(diào)用StiReportResponse類的PrintAsHtml()靜態(tài)方法。報表將自動生成,導(dǎo)出為HTML并發(fā)送以進行打印 - 將顯示系統(tǒng)打印對話框。
protected void ButtonPrintHtml_Click(object sender, EventArgs e)
{
StiReport report = this.GetReport();
StiReportResponse.PrintAsHtml(report);
}
要獲取報表,使用了GetReport()方法。此方法加載報表模板,加載XML數(shù)據(jù)文件并為加載的報表注冊此數(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),請點擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn