翻譯|使用教程|編輯:王香|2018-10-08 13:25:06.000|閱讀 488 次
概述:在Stimulsoft顯示如何將報表導(dǎo)出為各種格式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載Stimulsoft Reports.Net最新版本】
此示例項目顯示如何將報表導(dǎo)出為各種格式。對于此操作,只需使用實現(xiàn)所有導(dǎo)出格式的方法的特殊StiReportResponse類即可。這些方法接受所有必要參數(shù)的輸入以配置導(dǎo)出。 例如,為各種報表實現(xiàn)幾種流行的導(dǎo)出格式。在ASPX頁面上添加選擇列表,還添加導(dǎo)出按鈕并在Web查看器中調(diào)用報表的預(yù)覽頁面。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Export_Report_from_Code.Default" %> <!DOCTYPE html> <html xmlns="//www.w3.org/1999/xhtml"> <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事件中加載報表,連接到數(shù)據(jù)并以所選格式導(dǎo)出報表。使用StiReportResponse類的靜態(tài)方法導(dǎo)出報表。
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(@"Data\Demo.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"); }
示例代碼的結(jié)果如下圖所示:
購買Stimulsoft正版授權(quán),請點擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn