LocalReport.Render 方法 (String, String, String, String, String, String[], Warning[])
处理报表,并以指定的格式呈现报表。
命名空间: Microsoft.Reporting.WinForms
程序集: Microsoft.ReportViewer.WinForms(在 microsoft.reportviewer.winforms.dll 中)
public override byte[] Render ( string format, string deviceInfo, [OutAttribute] ref string mimeType, [OutAttribute] ref string encoding, [OutAttribute] ref string fileNameExtension, [OutAttribute] ref string[] streams, [OutAttribute] ref Warning[] warnings )
参数
format呈现报表所用格式。此参数映射到一个呈现扩展插件。支持的格式包括 Excel、PDF 和 Image。
包含设备特定内容的 XML 字符串,该内容是格式参数中指定的呈现扩展插件所需的。有关特定输出格式的设备信息设置的详细信息,请参阅 SQL Server 2005 Reporting Services 文档中的“设备信息设置”。
[out] 呈现的报表的 MIME 类型。
[out] 呈现报表的内容时使用的编码。
[out] 用于输出文件的文件扩展名。
[out] 流标识符。您可以使用它们来呈现与报表相关联的外部资源(例如,图像)。
[out] 描述报表处理期间出现的任何警告的一组 Warning 对象。
返回值
采用指定格式的报表的 Byte 数组。示例
以下代码示例假定一个包含 ReportViewer 控件和按钮的 Windows 窗体应用程序。该代码显示了加载到控件中并在其中呈现的本地报表,以及用于将报表导出为 Microsoft Excel 格式的Render 方法。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Reporting.WinForms; using System.IO; namespace SampleCode { public partial class Form1 : Form { private DataTable LoadSalesData() { // Load data from XML file. DataSet dataSet = new DataSet(); dataSet.ReadXml(@"c:\Reports\data.xml"); return dataSet.Tables[0]; } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.reportViewer1.ProcessingMode = ProcessingMode.Local; this.reportViewer1.LocalReport.ReportPath = @"c:\Reports\Report1.rdl"; reportViewer1.LocalReport.DataSources.Add( new ReportDataSource("Sales", LoadSalesData())); this.reportViewer1.RefreshReport(); } private void button1_Click(object sender, EventArgs e) { Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes = reportViewer1.LocalReport.Render( "Excel", null, out mimeType, out encoding, out extension, out streamids, out warnings); FileStream fs = new FileStream(@"c:\output.xls", FileMode.Create); fs.Write(bytes, 0, bytes.Length); fs.Close(); MessageBox.Show("Report exported to output.xls", "Info"); } } }
相关链接:http://msdn.microsoft.com/zh-cn/library/ms252207(VS.80).aspx