【Stimulsoft Reports.Net教程】从代码打印报表

下载Stimulsoft Reports.Net最新版本

特殊的StiReportResponse类包含两种报表打印模式:打印为PDF并以HTML 格式打印。例如,为一个报表实现这些模式以便比较它们。为每种打印模式添加两个按钮,并为这些按钮添加单击事件处理程序。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Print_Report_from_Code.Default" %>
 
<!DOCTYPE html>
 
<html xmlns="http://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事件中,它获取报表并调用StiReportResponse类的PrintAsPdf()静态方法。报表将自动生成,导出为PDF并发送打印 - 将显示系统打印对话框。

protected void ButtonPrintPdf_Click(object sender, EventArgs e)
{
    StiReport report = this.GetReport();
 
    StiReportResponse.PrintAsPdf(report);
}

在ButtonPrintHtml_Click事件中,它获取报表并调用StiReportResponse类的PrintAsHtml()静态方法。报表将自动生成,导出为HTML并发送以进行打印 - 将显示系统打印对话框。

protected void ButtonPrintHtml_Click(object sender, EventArgs e)
{
    StiReport report = this.GetReport();
 
    StiReportResponse.PrintAsHtml(report);
}

要获取报表,使用了GetReport()方法。此方法加载报表模板,加载XML数据文件并为加载的报表注册此数据。

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;
}

示例代码的结果如下图所示:

Stimulsoft

查看原文,下载示例

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值