LocalReport 類別
代表在本機進行處理和轉譯而並未連接到報表伺服器的報表。
命名空間: Microsoft.Reporting.WinForms
組件: Microsoft.ReportViewer.WinForms (在 microsoft.reportviewer.winforms.dll)
語法
'宣告
<SerializableAttribute> _
Public NotInheritable Class LocalReport
Inherits Report
Implements ISerializable
'用途
Dim instance As LocalReport
[SerializableAttribute]
public sealed class LocalReport : Report, ISerializable
[SerializableAttribute]
public ref class LocalReport sealed : public Report, ISerializable
/** @attribute SerializableAttribute() */
public final class LocalReport extends Report implements ISerializable
SerializableAttribute
public final class LocalReport extends Report implements ISerializable
備註
LocalReport 類別代表在本機進行處理和轉譯而並未連接到報表伺服器的報表。這個類別是 ReportViewer 控制項所用的相同物件,不過,它也可以當作封裝了 ReportViewer 控制項核心功能的非視覺化物件來獨立使用。
LocalReport 物件可以從檔案系統中開啟用戶端報表定義 (RDLC) 檔案,您也可以將 RDLC 檔案當作 Stream 或 TextReader 來提供給它。
LocalReport 物件沒有執行查詢或提取資料的能力;相反地,資料必須以 ADO.NET DataTables 執行個體或商務物件集合的方式來提供給它。
LocalReport 物件支援報表參數,但不支援查詢參數。
範例
下列程式碼片段利用 LocalReport 物件來載入和匯出報表。
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Reporting.WinForms.LocalReport lr = new Microsoft.Reporting.WinForms.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);
fs.Close();
}
}
Private Sub Button1_Click(ByVal sender As System.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()
deviceInfo = "< deviceInfo ><SimplePageHeaders>True</SimplePageHeaders></DeviceInfo>"
bytes = ReportViewer1.LocalReport.Render("Excel", Nothing, _
mimeType,encoding, extension, streamids, warnings)
Dim fs As New FileStream("c:\output.xls", FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
MessageBox.Show("Report exported to output.xls", "Info")
End Sub
繼承階層
System.Object
Microsoft.Reporting.WinForms.Report
Microsoft.Reporting.WinForms.LocalReport
執行緒安全性
此類型的任何公用靜態 (在 Visual Basic 中為 Shared ) 成員為安全執行緒。任何執行個體成員皆不能保證是安全執行緒。