【Stimulsoft Reports.Net教程】代码导出 表

在Stimulsoft显示如何将 表导出为各种格式。

【下载Stimulsoft Reports.Net最新版本】

此示例项目显示如何将 表导出为各种格式。对于此操作,只需使用实现所有导出格式的方法的特殊StiReportResponse类即可。这些方法接受所有必要参数的输入以配置导出。 例如,为各种 表实现几种流行的导出格式。在ASPX页面上添加选择列表,还添加导出按钮并在Web查看器中调用 表的预览页面。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Export_Report_from_Code.Default" %><!DOCTYPE html><html ><head runat="server">    <title>Export Report from Code</title></head><body>    <form id="form1" runat="server">    <h2><span style="color: #0066ff">Export Example</span></h2>    <table>        <tr>            <td width="200px">                <strong>Select Report:</strong>            </td>            <td width="200px">                <strong>Select Output Format:</strong>            </td>        </tr>        <tr>            <td>                <asp:ListBox ID="ListBoxReports" runat="server" Height="100px">                    <asp:ListItem Selected="True">Anchors</asp:ListItem>                    <asp:ListItem>MasterDetail</asp:ListItem>                    <asp:ListItem>MultiColumnList</asp:ListItem>                    <asp:ListItem>SimpleGroup</asp:ListItem>                    <asp:ListItem>SimpleList</asp:ListItem>                </asp:ListBox>            </td>            <td>                <asp:ListBox ID="ListBoxFormats" runat="server" Height="100px">                    <asp:ListItem Selected="True">Pdf</asp:ListItem>                    <asp:ListItem>Html</asp:ListItem>                    <asp:ListItem>Xls</asp:ListItem>                    <asp:ListItem>Txt</asp:ListItem>                    <asp:ListItem>Rtf</asp:ListItem>                </asp:ListBox>            </td>        </tr>        <tr>            <td>                <asp:Button ID="ButtonPreview" runat="server" Text="Preview" onclick="ButtonPreview_Click" />            </td>            <td>                <asp:Button ID="ButtonExport" runat="server" Text="Export" onclick="ButtonExport_Click" />            </td>        </tr>    </table>    </form></body></html>

在ButtonExport_Click事件中加载 表,连接到数据并以所选格式导出 表。使用StiReportResponse类的静态方法导出 表。

protected void ButtonExport_Click(object sender, EventArgs e){    StiReport report = new StiReport();    DataSet data = new DataSet();    report.Load(Server.MapPath(String.Format("Reports\{0}.mrt", ListBoxReports.SelectedItem.Text)));    data.ReadXml(Server.MapPath(@"DataDemo.xml"));    report.RegData(data);    switch (ListBoxFormats.SelectedIndex)    {        case 0:            StiReportResponse.ResponseAsPdf(report);            break;        case 1:            StiReportResponse.ResponseAsHtml(report);            break;        case 2:            StiReportResponse.ResponseAsXls(report);            break;        case 3:            StiReportResponse.ResponseAsText(report);            break;        case 4:            StiReportResponse.ResponseAsRtf(report);            break;    }}

所选 表可以显示在查看器中。为此,请使用ButtonPreview_Click事件,该事件将 表名称保存在会话中,并使用 表查看器重定向到Report.aspx页面。

protected void ButtonPreview_Click(object sender, EventArgs e){    Session["reportname"] = ListBoxReports.SelectedItem.Text;    Response.Redirect("Report.aspx");}

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

Stimulsoft

下载示例

购买Stimulsoft正版授权,请点击“咨询在线客服”哟!

FastReport2018.4

标签: 表解决方案 表 表控件 表设计stimulsoft report .netStimulsoft

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年9月5日
下一篇 2018年9月5日

相关推荐

发表回复

登录后才能评论