Easy Exporting To Disk
There is one method that makes exporting easy: ExportToDisk(). Without a doubt, the ExportToDisk() method is the most popular way of exporting a report because you are only required to specify the format type and the filename. The following code shows an example or saving a report as a PDF file. You can see that only one line of code is required to export the report to a PDF formatted file.
myReport.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "C:\Report.PDF")
The first parameter uses the ExportFormatType enumeration to specify the format the file should be saved in and the second parameter is the file name. The ExportToDisk() method supports the most common formats used for viewing files. Table 19-2 lists the format and enumeration constants associated with each. They are within the namespace CrystalDecisions.Shared.ExportFormatType.
Table 19-2. Enumeration constants for the export format.
Format | File Extension | Enumeration Constant |
---|---|---|
Adobe Acrobat | PortableDocFormat | |
Rich Text Format | .RTF | RichText |
HTML 3.2 | .HTM / .HTML | HTML32 |
HTML 4.0 | .HTM / .HTML | HTML40 |
MS Word | .DOC | WordForWindows |
MS Excel | .XLS | Excel |
MS Excel | .XLS | ExcelRecord (data only) |
Crystal Reports | .RPT | CrystalReport |
The drawback to using the ExportToDisk() method is that it doesn’t have any parameters for customizing the export format. For example, there is no way to specify the page range. To customize the report format that gets exported, you have to use the more advanced features found in the Export() method.