This walkthrough illustrates how to export a report to PDF, HTML, RTF, Text, TIFF and Excel files.
This walkthrough is split up into the following activities:
- Adding an ActiveReport to a Visual Studio project
- Adding the appropriate export filters to your project
- Connecting the report to a data source
- Adding controls to display the data
- Using the export methods to export data to all available file formats
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have completed this walkthrough, you will have created PDF, HTML, RTF, Text, TIFF and Excel files which can be found in the Bin/Debug (C#) or Bin (VB.NET) subfolder of your project's folder.
Adding an ActiveReport to a Visual Studio project
To add an ActiveReport to your project
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptExports.
- Click Open.
Adding the export filters to your project
To add the export filters to your project
- Click on the following export controls one at a time in the appropriate toolbox to select them.
- HtmlExport
- PdfExport
- RtfExport
- TextExport
- TiffExport
- XlsExport
- Drag each control onto the Windows Form.
- The controls will appear in the component tray underneath the Windows Form.
Connecting the report to a data source
To connect the report to a data source
- Return to the report and click the gray report DataSource icon in the Detail section to open the Report Datasource dialog.
- Select the "OLE DB" tab.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "Select LastName, FirstName from Employees."
- Click OK to return to the report design surface.
Adding controls to display the data
To add controls to the report
- In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the following properties of each textbox as indicated.
Field Text Location LastName Last Name 0.06, 0.06 FirstName First Name 1.188, 0.063
Using the export methods to export files to all available file formats
To write the code in Visual Basic or C#
- In the Designer view of the Windows Form, double-click the form to create an event-handling method for the Form_Load event. Add code to the handler to:
- Export the report to all available file formats
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim rpt As New rptExports() rpt.Run() Me.HtmlExport1.Export(rpt.Document, Application.StartupPath + "\\HTMLExpt.html") Me.PdfExport1.Export(rpt.Document, Application.StartupPath + "\\PDFExpt.pdf") Me.RtfExport1.Export(rpt.Document, Application.StartupPath + "\\RTFExpt.rtf") Me.TextExport1.Export(rpt.Document, Application.StartupPath + "\\TextExpt.txt") Me.TiffExport1.Export(rpt.Document, Application.StartupPath + "\\TIFFExpt.tiff") Me.XlsExport1.Export(rpt.Document, Application.StartupPath + "\\XLSExpt.xls") End Sub
//C# private void Form1_Load(object sender, System.EventArgs e) { rptExports rpt = new rptExports(); rpt.Run(); this.htmlExport1.Export(rpt.Document, Application.StartupPath + "\\HTMLExpt.html"); this.pdfExport1.Export(rpt.Document, Application.StartupPath + "\\PDFExpt.pdf"); this.rtfExport1.Export(rpt.Document, Application.StartupPath + "\\RTFExpt.rtf"); this.textExport1.Export(rpt.Document, Application.StartupPath + "\\TextExpt.txt"); this.tiffExport1.Export(rpt.Document, Application.StartupPath + "\\TIFFExpt.tiff"); this.xlsExport1.Export(rpt.Document, Application.StartupPath + "\\XLSExpt.xls"); }
Build the project then navigate to the appropriate folder to see each export.