ActiveReports提供多种导出过滤器用于导出页面、区域、RDL报表所支持的文件格式。如HTML、PDF、RTF、Text、TIFF、Excel。
需要注意的是HTML 导出需要.NET FRAMEWORK 完整版,以下是导出报表的核心步骤。
1. 添加引用
GrapeCity.ActiveReports.Export.Excel.v10 GrapeCity.ActiveReports.Export.Html.v10 GrapeCity.ActiveReports.Export.Image.v10 GrapeCity.ActiveReports.Export.Pdf.v10 GrapeCity.ActiveReports.Export.Word.v10 GrapeCity.ActiveReports.Export.Xml.v10
2. 在FORM_LOAD 事件中创建报表对象
添加RDL报表
VB 语言:
' Create a page/Rdl report.Dim rpt As New GrapeCity.ActiveReports.PageReport()' Load the report you want to export.' For the code to work, this report must be stored in the bin\debug folder of your project.rpt.Load(New System.IO.FileInfo ("report.rdlx"))
Dim MyDocument As New GrapeCity.ActiveReports.Document.PageDocument (rpt)
C# 语言:
// Create a page/Rdl report.
GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport();
// Load the report you want to export.
// For the code to work, this report must be stored in the bin\debug folder of your project.
rpt.Load(new System.IO.FileInfo ("report.rdlx"));GrapeCity.ActiveReports.Document.PageDocument MyDocument = new GrapeCity.ActiveReports.Document.PageDocument (rpt);
添加区域报表:
VB语言:
' Create a Section report.Dim rpt As New GrapeCity.ActiveReports.SectionReport()' For the code to work, report.rpx must be placed in the bin\debug folder of your project.Dim xtr As New System.Xml.XmlTextReader(Application.StartupPath + "\report.rpx")rpt.LoadLayout(xtr)rpt.Run()
C#语言:
// Create a Section report.GrapeCity.ActiveReports.SectionReport rpt = new GrapeCity.ActiveReports.SectionReport();
// For the code to work, report.rpx must be placed in the bin\debug folder of your project.
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Application.StartupPath + "\\report.rpx");rpt.LoadLayout(xtr);rpt.Run();
3. 添加代码导出页面/RDL 报表,区域报表,以下代码在.rpx和rdlx文件中是通用的。
VB:
' Export the report in HTML format.
Dim HtmlExport1 As New GrapeCity.ActiveReports.Export.Html.Section.HtmlExport()HtmlExport1.Export(MyDocument, Application.StartupPath + "\HTMLExpt.html")
' Export the report in PDF format.
Dim PdfExport1 As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport()PdfExport1.Export(MyDocument, Application.StartupPath + "\PDFExpt.pdf")
' Export the report in RTF format.
Dim RtfExport1 As New GrapeCity.ActiveReports.Export.Word.Section.RtfExport()RtfExport1.Export(MyDocument, Application.StartupPath + "\RTFExpt.rtf")
' Export the report in text format.
Dim TextExport1 As New GrapeCity.ActiveReports.Export.Xml.Section.TextExport()TextExport1.Export(MyDocument, Application.StartupPath + "\TextExpt.txt")
' Export the report in TIFF format.
Dim TiffExport1 As New GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport()TiffExport1.Export(MyDocument, Application.StartupPath + "\TIFFExpt.tiff")
' Export the report in Excel format.
Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()' Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.XlsxXlsExport1.Export(MyDocument, Application.StartupPath + "\XLSExpt.xlsx")
C#语言
// Export the report in HTML format.
GrapeCity.ActiveReports.Export.Html.Section.HtmlExport HtmlExport1 = new GrapeCity.ActiveReports.Export.Html.Section.HtmlExport();
HtmlExport1.Export(MyDocument, Application.StartupPath + "\\HTMLExpt.html");
// Export the report in PDF format.
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport PdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
PdfExport1.Export(MyDocument, Application.StartupPath + "\\PDFExpt.pdf");
// Export the report in RTF format.
GrapeCity.ActiveReports.Export.Word.Section.RtfExport RtfExport1 = new GrapeCity.ActiveReports.Export.Word.Section.RtfExport();
RtfExport1.Export(MyDocument, Application.StartupPath + "\\RTFExpt.rtf");
// Export the report in text format.
GrapeCity.ActiveReports.Export.Xml.Section.TextExport TextExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
TextExport1.Export(MyDocument, Application.StartupPath + "\\TextExpt.txt");
// Export the report in TIFF format.
GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport TiffExport1 = new GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport();
TiffExport1.Export(MyDocument, Application.StartupPath + "\\TIFFExpt.tiff");
// Export the report in XLSX format.
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
// Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.
XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;XlsExport1.Export(MyDocument, Application.StartupPath + "\\XLSExpt.xlsx");
您在使用产品过程中有任何疑问,可以登录葡萄城开发者社区和经验丰富的技术工程师、ActiveReports开发人员交流:了解更多。
了解ActiveReports产品更多特性:
下载产品体验产品功能: