Exporting a Report

Crystal Reports .NET features a rich export functionality, which is partially exposed in the Crystal Report Viewer. From the viewer, we can call the ExportReport method to open a Save as... and export your report into one of four formats:

In compatibility testing, the export formats for Microsoft Word and Excel work well with Office 97+, and Rich Text Format can be used by just about any word-processing application (including Word, WordPad, WordPerfect, and so on). For Adobe Acrobat, a version 3.0 or above reader is recommended and the output is consistent across version 3.0-6.0.

So, let's put this functionality into our custom viewer. Drag and drop a button onto the form once more, this time calling it Export_Button and setting the text to Export. Once again, click the button to open its code event. Insert the following:

CrystalReportViewer1.ExportReport()

When the ExportReport method is used, the shown in Figure 4-22 will appear and allow you to select an export format from a drop-down list and select where the file is to be saved.

Once the file has been saved, a message box will appear, advising you that the export is complete. You can then use the associated application to open the exported file.

Was this article helpful?

0 0

Post a comment