Exporting with Programming Code
Using the built-in export feature of the Windows 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.
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 a Stream object. The second questions is what is the format that the report should be exported to. There are 6 formats that reports can be converted to: PDF files, RTF, MS Word, MS Excel, HTML 3.2 and HTML 4.0. These two questions are independent of each other and are programmed differently. Figure 19-3 shows how this all fits together.
Figure 19-3. 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() | Export a report to any of the available export formats using the properties of the ExportOptions object. |
ExportToDisk(FormatType, Filename) | Export a report to a disk file with no additional coding. |
ExportToStream(FormatType) | Exports a report to a stream and returns the stream to the caller. |