报表导出 

在区域报表中,你可以将报表导出为多种格式的文件,在使用导出功能之前你需要在工程中添加相应的DLL引用,或者从工具箱中添加相应的控件。以下是在区域报表中支持的导出格式:

l HTML

l PDF

l RTF

l Text

l TIFF

l Excel

注意:HTML导出需要 .NET Framework full profile 版本。

 

按照以下步骤可以完成报表的导出操作:

1、确保报表文件 report.rpx 被包含在你工程的 Bin 目录下的 Debug 文件夹中。

2、在解决方案资源管理器中,鼠标右键并选择添加引用选项。

3、在添加引用对话框中找到以下DLL,并点击确定按钮将其添加到工程中。

GrapeCity.ActiveReports.Export.Excel.v9

GrapeCity.ActiveReports.Export.Html.v9

GrapeCity.ActiveReports.Export.Image.v9

GrapeCity.ActiveReports.Export.Pdf.v9

GrapeCity.ActiveReports.Export.Word.v9

GrapeCity.ActiveReports.Export.Xml.v9

注意:如果你是从Visual Studio 工具箱中拖动导出控件到窗体上,此时系统会自动为你的工程添加相应DLL的引用,你可以跳过第2、3步操作。

4、双击窗体以创建 Load 事件的处理函数。

5、将以下代码添加到 Form_Load 函数中,以实现报表的导出操作:

 

Visual Basic.NET 代码,请粘贴到 Form_Load 函数中

Dim rpt As New GrapeCity.ActiveReports.SectionReport()

Dim xtr As New System.Xml.XmlTextReader(Application.StartupPath +"\report.rpx")

rpt.LoadLayout(xtr)

rpt.Run()

 

Dim htmlExport1 As New GrapeCity.ActiveReports.Export.Html.Section.HtmlExport()

htmlExport1.Export(rpt.Document, Application.StartupPath + "\\HTMLExpt.html")

 

Dim pdfExport1 As New GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport()

pdfExport1.Export(rpt.Document, Application.StartupPath + "\\PDFExpt.pdf")

 

Dim rtfExport1 As New GrapeCity.ActiveReports.Export.Word.Section.RtfExport()

rtfExport1.Export(rpt.Document, Application.StartupPath + "\\RTFExpt.rtf")

 

Dim textExport1 As New GrapeCity.ActiveReports.Export.Xml.Section.TextExport()

textExport1.Export(rpt.Document, Application.StartupPath + "\\TextExpt.txt")

 

Dim tiffExport1 As New

GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport()

tiffExport1.Export(rpt.Document, Application.StartupPath + "\\TIFFExpt.tiff")

 

Dim xlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()

xlsExport1.FileFormat =GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx

 

xlsExport1.Export(rpt.Document, Application.StartupPath + \\XLSExpt.xlsx)

C# 代码,请粘贴到 Form_Load 函数中

GrapeCity.ActiveReports.SectionReport rpt = new

GrapeCity.ActiveReports.SectionReport();

 

System.Xml.XmlTextReader xtr = new

System.Xml.XmlTextReader(Application.StartupPath + "\\report.rpx");

rpt.LoadLayout(xtr);

rpt.Run();

 

GrapeCity.ActiveReports.Export.Html.Section.HtmlExport htmlExport1 = new

GrapeCity.ActiveReports.Export.Html.Section.HtmlExport();

htmlExport1.Export(rpt.Document, Application.StartupPath + "\\HTMLExpt.html");

 

GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new

GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();

pdfExport1.Export(rpt.Document, Application.StartupPath + "\\PDFExpt.pdf");

 

GrapeCity.ActiveReports.Export.Word.Section.RtfExport rtfExport1 = new

GrapeCity.ActiveReports.Export.Word.Section.RtfExport();

rtfExport1.Export(rpt.Document, Application.StartupPath + "\\RTFExpt.rtf");

 

GrapeCity.ActiveReports.Export.Xml.Section.TextExport textExport1 = new

GrapeCity.ActiveReports.Export.Xml.Section.TextExport();

textExport1.Export(rpt.Document, Application.StartupPath + "\\TextExpt.txt");

 

GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport tiffExport1 = new

GrapeCity.ActiveReports.Export.Image.Tiff.Section.TiffExport();

tiffExport1.Export(rpt.Document, Application.StartupPath + "\\TIFFExpt.tiff");

 

GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new

GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();

xlsExport1.FileFormat =

GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;

 

xlsExport1.Export(rpt.Document, Application.StartupPath + "\\XLSExpt.xlsx");

6、按下F5键运行应用程序,可以在工程 bin\debug 目录下找到导出的报表文件。