使用Export Filters 导出报表

ActiveReports提供多种导出过滤器用于导出页面、区域、RDL报表所支持的文件格式。如HTML、PDF、RTF、Text、TIFF、Excel。

发布于 2016/07/30 00:00

ActiveReports

 

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.Xlsx
XlsExport1.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产品更多特性:

/developer/activereports

下载产品体验产品功能:

/download/?pid=16

ActiveReports 报表控件| 下载试用

ActiveReports 是一款专注于 .NET 平台的报表控件,全面满足 HTML5 / WinForm / ASP.NET / ASP.NET MVC / WPF 等平台下报表设计和开发工作需求,作为专业的报表工具为全球超过 300,000 开发人员提供了全面的报表开发服务。

您对ActiveReports产品的任何技术问题,都有技术支持工程师提供1对1专业解答,点击此处即可发帖提问>>技术支持论坛

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

活字格低代码二维码

关注“活字格低代码”

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态