LocalReport 类
表示不用连接到报表服务器而在本地处理和呈现的报表。
继承层次结构
System.Object
Microsoft.Reporting.WebForms.Report
Microsoft.Reporting.WebForms.LocalReport
命名空间: Microsoft.Reporting.WebForms
程序集: Microsoft.ReportViewer.WebForms(在 Microsoft.ReportViewer.WebForms.dll 中)
语法
声明
<SerializableAttribute> _
Public NotInheritable Class LocalReport _
Inherits Report _
Implements ISerializable, IDisposable
用法
Dim instance As LocalReport
[SerializableAttribute]
public sealed class LocalReport : Report,
ISerializable, IDisposable
[SerializableAttribute]
public ref class LocalReport sealed : public Report,
ISerializable, IDisposable
[<SealedAttribute>]
[<SerializableAttribute>]
type LocalReport =
class
inherit Report
interface ISerializable
interface IDisposable
end
public final class LocalReport extends Report implements ISerializable, IDisposable
LocalReport 类型公开以下成员。
构造函数
名称 | 说明 | |
---|---|---|
LocalReport | 初始化 LocalReport 类的一个新实例。 |
页首
属性
名称 | 说明 | |
---|---|---|
DataSources | 获取报表使用的数据源集合。 | |
DisplayName | 获取或设置报表的显示名称。 (从 Report 继承。) | |
EnableExternalImages | 指示在报表包含外部图像时是否可以呈现。 | |
EnableHyperlinks | 指示在报表包含超链接操作时是否可以呈现。 | |
IsDrillthroughReport | 指示该报表是否为钻取报表。 (从 Report 继承。) | |
IsReadyForRendering | 获取一个 Boolean 值,该值指示是否已指定报表定义及所有参数,以及是否所有数据源已经可供使用。 (从 Report 继承。) | |
OriginalParametersToDrillthrough | 返回从父报表传递到此报表(如果它是钻取报表)的参数。 | |
ReportEmbeddedResource | 获取或设置报表嵌入资源的名称。 | |
ReportPath | 获取或设置本地报表的本地文件系统路径。 | |
ShowDetailedSubreportMessages | 获取或设置一个 Boolean 值,该值指示当子报表中出错时是否应显示详细消息。 |
页首
方法
页首
事件
名称 | 说明 | |
---|---|---|
SubreportProcessing | 在处理子报表时发生。 |
页首
显式接口实现
名称 | 说明 | |
---|---|---|
ISerializable.GetObjectData |
页首
注释
LocalReport 类表示不用连接到报表服务器而在本地处理和呈现的报表。此类与**“ReportViewer”控件所使用的对象相同,但它还可以作为非可视对象(包装“ReportViewer”**控件的核心功能)独立使用。
LocalReport 对象可以打开文件系统中或嵌入的资源中的客户端报表定义 (RDLC) 文件,或者 RDLC 文件可以作为 Stream 或 TextReader 提供给该对象。
LocalReport 对象无法执行查询或提取数据;数据源必须添加到 DataSources 集合属性。
LocalReport 对象支持报表参数,但是不支持参数提示
示例
在下面的代码示例中,使用一个 LocalReport 对象加载和导出报表。
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.Reporting.WebForms.LocalReport lr =
new Microsoft.Reporting.WebForms.LocalReport();
string deviceInfo =
"<DeviceInfo>" +
"<SimplePageHeaders>True</SimplePageHeaders>" +
"</DeviceInfo>";
lr.ReportPath = @"C:\My Reports\Monthly Sales.rdlc";
lr.DataSources.Add(new ReportDataSource("Sales", GetSalesData()));
byte[] bytes = lr.Render("Excel", deviceInfo, out mimeType,
out encoding, out streamids, out warnings);
using (FileStream fs = new FileStream(@"c:\My Reports\Monthly Sales.xls", FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
}
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 deviceInfo as string
Dim bytes As Byte()
Dim lr As New Microsoft.Reporting.WebForms.LocalReport
lr.ReportPath = "C:\My Reports\Monthly Sales.rdlc"
lr.DataSources.Add(New ReportDataSource("Sales", GetSalesData()))
deviceInfo = _
"<DeviceInfo><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = ReportViewer1.LocalReport.Render("Excel", deviceInfo,_
mimeType, encoding, extension, streamids, warnings)
Dim fs As New FileStream("c:\output.xls", FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
End Sub
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。