How to Export Crystal Report

Crystal Report supports export of Reports in many formats. In these tutorials let us explore how to export Crystal report using the various options available in Crystal Reports.

You can look at the various export formats that are supported by the Crystal Report from the tutorials Crystal Report Export formats

If you are new to Crystal Report you can look at our following tutorials to get started

  1. How to Create Crystal Report Using Visual Studio
  2. How to Create Crystal Report Using ASP.NET Webforms
  3. How to Create Crystal Report Using ASP.NET MVC and ADO.NET Entity Model

How to Export Crystal Report

Crystal Report can be exported in two ways

  1. Using Crystal Viewer Control.
  2. Using the method provided in Report Document Object (SDK).

Crystal Report Viewer Control

Crystal Report Viewer control is a .NET control. You can add it to your windows form or to web form so that you can display the report to the user.   You can add this control to the form by dragging it from the toolbox.

Crystal Report viewer control displays the report to the user at runtime. It has the option to print, search, browse through the pages of the report.  It has also had the option to export the report.  This Option found at the top left corner of the Report

To Export to The Report do the following

Export Crystal Report Using Web Application

Export Crystal Report in Web application
Export Crystal Report in Web application
  1. Run your Crystal Report Project.
  2. Select the Export Report button at the top Left Corner.
  3. From the File Format Drop drown select appropriate format.
  4. From Page Range Option Select All Pages
    If you want print selected pages choose Select Pages and enter the from  and to page No. Note that some of the file formats has this feature disabled
  5. Click on Export.
  6. File is downloaded.

Export Crystal Report Using Windows Application

Export Crystal Report in Windows Application

Export Crystal Report in Windows Application

  1. Run your Crystal Report Project
  2. Select the Export Report button at the top Left Corner
  3. From the Save as Drop drown select appropriate format
  4. Note that Page Range option is not provided in the windows version of Crystal Report Viewer Control
  5. In File Name Option enter the name of the file
  6. Click on Save

Export Crystal Report Using Report Document (SDK)

Another way to Export crystal report is using the Methods provided in Report Document object. This option gives us the most flexibility when comes to exporting the report.

All the methods are available in the Namespace CrystalDecisions.CrystalReports.Engine which is contained in the assembly (dll) CrystalDecisions.CrystalReports.Engine.dll

Here is the list of Methods available in the SDK.

ExportToDisk

Use this option to export the report to disk. Method has following Option

The above function takes two parameters. formatType and fileName

formatType

The format type to export the report. FormatType could be PDF, Excel etc. This parameter is explained in detail below

fileName

The file name to export the report with full path

ExportToHttpResponse

This Exports a report to the response object in the format specified. This Function has two variants (overloads)

This function has four parameters. formatType (Options in the second variant) ,respone,asAttachment,attachmentName

formatType

The format type to export the report.  FormatType could be PDF, Excel etc.. This parameter is explained later in the tutorial

options

The export options of the report.

response

The http response object of the page.

asAttachment

Indicates whether or not the report will be exported as an attachment of the response.

attachmentName

The file name to export the report.

ExportToStream

The report is sent to the stream. This function returns the stream object.

This function has one parameter formatType and returns stream

formatType

The format type to export the report.  FormatType cohasbe PDF, Excel etc. This option was explained later in the tutorial.

Return Value
A stream that contains the exported report as a sequence of bytes.

Export

This function has one parameter Options.

options

Exports a report to a format and destination specified within the ExportOptions. This parameter is explained below.

Parameters Explained

formatType

Crystal Report supports following Export Format Types. These all reside under the namespace CrystalDecisions.Shared.ExportFormatType

Format TypeDescription
CharacterSeparatedValuesExport as Character Seperated Values
CrystalReportSave as Crystal Report (.rpt) Files With Data
EditableRTFExport To Editable RTF File
ExcelExport to Excel (.xls format)
ExcelRecordExport to Excel (.xls format) without formatting
ExcelWorkbookExport to Excel (.xlsx format)   without formatting
HTML32Export to HTML 3.2 Format
HTML40Export to HTML 4.0 format
PortableDocFormatExport to PDF
RichTextExport to Rich Text
RPTRExport Crystal RPTR format
TabSeperatedTextExport to Tab separated Text file
TextExport to Ext file
WordForWindowsExport to Microsoft Word
XmlExport to XML Format

Read our post  Crystal Report Export formats for more information on each of these export formats

Options:

This export options found in the namespace CrystalDecisions.Shared.ExportOptions class. This class Has following members

ExportDestinationType
Gets or sets the options for the destination Type of the export for the report. The following Destinations are available to the report.

  1. ExportDestinationType.DiskFile
  2. ExportDestinationType.ExchangeFolder
  3. ExportDestinationType.MicrosoftMail

ExportDestinationOptions
Gets or sets the options for the destination of the export for the report. The following Destination are available to the report.

  1. ExchangeFolderDestinationOptions
  2. MicrosoftMailDestinationOptions
  3. DiskFileDestinationOptions

ExportFormatType
Gets or sets the options for the format type of the export for the report. Available format types are listed in the previous section.

ExportFormatOptions
Gets or sets the options for the format options of the export for the report. Each of the format Types have their own format options like

  1. CharacterSeparatedValuesFormatOptions
  2. EditableRTFExportFormatOptions
  3. ExcelDataOnlyFormatOptions
  4. ExcelFormatOptions
  5. PdfFormatOptions
    etc.

Each of these have various properties like page Range etc. which you can set programmatically

Using the SDK

Exporting the Crystal Report using the SDK is very simple and straight forward. We have created an tutorial on How to Export Crystal Report to PDF to use these SDK.

1 thought on “How to Export Crystal Report”

  1. Can you please let me know which ExportOption i can use to export .xlsx in CrystalDecisions.Shared.ExportOptions.
    I am using two things in my code.
    CrystalDecisions.Shared.ExportFormatType and that you have mentioned i can use ExcelWorkBook.
    But what i can use for ExportOptions to export .xlsx

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top