Exporting with Programming Code
Using the built-in export feature of the Crystal Reports viewer is nice, but as in most things related to programming, what you get in ease of use you give up in functionality. To get the most functionality for exporting a report, you have to write the programming code yourself.
It is common to export a report and find out that either the parameters or login information is lost. This is because these parameters were set using the viewer object and the ReportDocument object is used to do the exporting. These objects are exclusive of each other. When exporting, always set all properties with the ReportDocument object.
Before exporting a report, you have to answer two questions. The first question is, what is the destination type. There are four destination types to choose from: Disk file, Exchange folder, Email attachment and an Http Response. The second question, what is the format that the report should be exported to. There are seven formats that reports can be converted to: PDF files, RTF, MS Word, MS Excel, MS Excel data only, HTML 3.2 and HTML 4.0. These two questions are independent of each other and are programmed differently. Figure 19-4 shows the exporting object model and how the different classes work together.
Figure 19-4. The Export object model.
The ReportDocument class has various methods and properties that are used to implement the export functionality of Crystal Reports. Table 19-1 lists each method available.
Table 19-1. Export methods of the ReportDocument class.
Method | Description |
---|---|
Export() | Exports a report to any of the available export formats using the properties of the ExportOptions object. |
ExportToDisk(ExportFormatType, Filename) | Exports a report to a disk file with no additional coding. |
ExportToHttpResponse(ExportOptions, HttpResponse, Boolean, String) | Exports a report via the HTTP Response object. Has the option to export the report as a file attachment. |