ReportViewer报表导出成Excel,Image,PDF---LocalReport.Render

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。

deviceInfo

包含设备特定内容的 XML 字符串,该内容是格式参数中指定的呈现扩展插件所需的。有关特定输出格式的设备信息设置的详细信息,请参阅 SQL Server 2005 Reporting Services 文档中的“设备信息设置”。

mimeType

[out] 呈现的报表的 MIME 类型。

encoding

[out] 呈现报表的内容时使用的编码。

fileNameExtension

[out] 用于输出文件的文件扩展名。

streams

[out] 流标识符。您可以使用它们来呈现与报表相关联的外部资源(例如,图像)。

warnings

[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
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值