Tutorial: Exporting to Multiple Formats

Introduction

In this tutorial, you learn how to export the report programmatically. Crystal Reports can export to a wide variety of formats. The options available to you depend on the version of Crystal Reports that you have installed.

Every version of Crystal Reports for Visual Studio supports the following export options:

  • Crystal Reports (RPT)
  • PDF
  • Rich Text Format (RTF)
  • Microsoft Word (97-2003)
  • Microsoft Excel (97-2003)
  • Microsoft Excel (97-2003) Data-Only
  • HTML 3.2
  • HTML 4.0

Crystal Reports Developer supports these additional formats:

  • Seperated Values (CSV)
  • Microsoft Word - Editable (RTF)
  • Tab Separated Text (TTX)
  • Text

You can select any of those formats, click the Export button for the CrystalReportViewer control, and export a report in the selected format to your local machine that runs Crystal Reports in a Web or Windows application.

You can also export reports programmatically, to specific directories on the local Web server or Windows machine.

To begin this tutorial, you add a DropDownList control to your Web or Windows Form, and then populate it with the values from the ExportFormatType enum in the CrystalDecisions.Shared namespace.

Then, you create three private helper methods that contain the export functionality and that perform specific configuration for each of the export formats.

Finally, you create a click event method from a Button control on the Web or Windows Form, and call the three private helper methods that perform the export.

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Web Site: CS_Web_RDObjMod_Export
  • C# Windows project: CS_Win_RDObjMod_Export
  • Visual Basic Web Site: VB_Web_RDObjMod_Export
  • Visual Basic Windows project: VB_Win_RDObjMod_Export

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section:

See Also