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
- How to Create Crystal Report Using Visual Studio
- How to Create Crystal Report Using ASP.NET Webforms
- 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
- Using Crystal Viewer Control.
- 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
- Run your Crystal Report Project.
- Select the Export Report button at the top Left Corner.
- From the File Format Drop drown select appropriate format.
- 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
- Click on Export.
- File is downloaded.
Export Crystal Report Using Windows Application
Export Crystal Report in Windows Application
- Run your Crystal Report Project
- Select the Export Report button at the top Left Corner
- From the Save as Drop drown select appropriate format
- Note that Page Range option is not provided in the windows version of Crystal Report Viewer Control
- In File Name Option enter the name of the file
- 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.
Use this option to export the report to disk. Method has following Option
public virtual void ExportToDisk (ExportFormatType formatType, string fileName);
The above function takes two parameters. formatType and fileName
The format type to export the report. FormatType could be PDF, Excel etc. This parameter is explained in detail below
The file name to export the report with full path
This Exports a report to the response object in the format specified. This Function has two variants (overloads)
public virtual void ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType formatType, System.Web.HttpResponse response,bool asAttachment,attachmentName);
public virtual void ExportToHttpResponse(CrystalDecisions.Shared.ExportOptions options,
System.Web.HttpResponse response,bool asAttachment,attachmentName);
This function has four parameters. formatType (Options in the second variant) ,respone,asAttachment,attachmentName
The format type to export the report. FormatType could be PDF, Excel etc.. This parameter is explained later in the tutorial
The export options of the report.
The http response object of the page.
Indicates whether or not the report will be exported as an attachment of the response.
The file name to export the report.
The report is sent to the stream. This function returns the stream object.
public virtual System.IO.Stream ExportToStream(CrystalDecisions.Shared.ExportFormatType formatType)
This function has one parameter formatType and returns stream
The format type to export the report. FormatType cohasbe PDF, Excel etc. This option was explained later in the tutorial.
A stream that contains the exported report as a sequence of bytes.
public virtual void Export(CrystalDecisions.Shared.ExportOptions options)
This function has one parameter Options.
Exports a report to a format and destination specified within the ExportOptions. This parameter is explained below.
Crystal Report supports following Export Format Types. These all reside under the namespace CrystalDecisions.Shared.ExportFormatType
|CharacterSeparatedValues||Export as Character Seperated Values|
|CrystalReport||Save as Crystal Report (.rpt) Files With Data|
|EditableRTF||Export To Editable RTF File|
|Excel||Export to Excel (.xls format)|
|ExcelRecord||Export to Excel (.xls format) without formatting|
|ExcelWorkbook||Export to Excel (.xlsx format) without formatting|
|HTML32||Export to HTML 3.2 Format|
|HTML40||Export to HTML 4.0 format|
|PortableDocFormat||Export to PDF|
|RichText||Export to Rich Text|
|RPTR||Export Crystal RPTR format|
|TabSeperatedText||Export to Tab separated Text file|
|Text||Export to Ext file|
|WordForWindows||Export to Microsoft Word|
|Xml||Export to XML Format|
Read our post Crystal Report Export formats for more information on each of these export formats
This export options found in the namespace CrystalDecisions.Shared.ExportOptions class. This class Has following members
Gets or sets the options for the destination Type of the export for the report. The following Destinations are available to the report.
Gets or sets the options for the destination of the export for the report. The following Destination are available to the report.
Gets or sets the options for the format type of the export for the report. Available format types are listed in the previous section.
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
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.