次の方法で共有


LocalReport.Render メソッド (String, String, out String, out String, out String, out String[], out Warning[])

Processes the report and renders it in the specified format.

名前空間: Microsoft.Reporting.WebForms
アセンブリ: Microsoft.ReportViewer.WebForms (microsoft.reportviewer.webforms.dll 内)

構文

'宣言
'使用

パラメータ

  • format
    The format in which to render the report. This argument maps to a rendering extension. Supported formats include Microsoft Office Excel, PDF, and Image.
  • deviceInfo
    An XML string that contains the device-specific content that is required by the rendering extension specified in the format parameter. For more information about device information settings for specific output formats, see "Device Information Settings" in SQL Server Books Online.
  • mimeType
    [out] The MIME type of the rendered report.
  • encoding
    [out] The encoding used when rendering the contents of the report.
  • fileNameExtension
    [out] The file name extension used for the output file.
  • streams
    [out] The stream identifiers. You can use them to render external resources (images, for example) that are associated with the report.
  • warnings
    [out] An array of Warning objects that describes any warnings that occurred during report processing.

戻り値

A Byte array of the report in the specified format.

解説

The Render method can be used to export and print a report.

The following code samples assume a Web form application with a ReportViewer control, a button, and a label. In this code example,a local report is loaded into and rendered in the control and then the Render method is used to export the report to Excel format.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    private DataTable LoadSalesData()
    {
        // Load data from XML file.
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\Reports\data.xml");
        return dataSet.Tables[0];
    }

    protected void Page_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()));

    }
    protected 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();

            Label1.Text = "Report exported to output.xls";

        }
 }
Imports System.IO
Imports System.Data
Imports Microsoft.Reporting.WebForms


Partial Class _Default
    Inherits System.Web.UI.Page

    Private Function LoadSalesData() As DataTable
        '' Load data from XML file
        Dim dataSet = New DataSet
        dataSet.ReadXml("c:\Reports\data.xml")
        Return dataSet.Tables(0)
    End Function

    Protected Sub Page_Load(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles Me.Load
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.ReportPath = _
              "c:\Reports\Report1.rdl"
        Dim myDataSource = New ReportDataSource("Sales", _
           LoadSalesData())
        ReportViewer1.LocalReport.DataSources.Add(myDataSource)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles Button1.Click
        Dim warnings As Warning() = Nothing
        Dim streamids As String() = Nothing
        Dim mimeType As String = Nothing
        Dim encoding As String = Nothing
        Dim extension As String = Nothing
        Dim bytes As Byte()

        bytes = ReportViewer1.LocalReport.Render("Excel", _
          Nothing, mimeType, _
            encoding, extension, streamids, warnings)

        Dim fs As New FileStream("c:\outputvb.xls", FileMode.Create)
        fs.Write(bytes, 0, bytes.Length)
        fs.Close()

        Label1.Text = "Report exported to output.xls"

    End Sub
End Class

参照

リファレンス

LocalReport クラス
LocalReport メンバ
Microsoft.Reporting.WebForms 名前空間