Export Crystal Reports in Asp.net

Source: Internet
Author: User

In fact, in a Windows form, the Crystal Report crystalreportviewer itself provides the export function, so you do not need to write anyCode.
However, in Asp.net, the export function of Crystal Reports is slightly different. A small amount of code is required. Below is a code template:

Public   Void Export ( String Filename, String EXT)
{
ReportDocument reportdocument = Getreportdocument ();
Exportoptions =   New Exportoptions ();
Diskfiledestinationoptions diskoptions = Exportoptions. creatediskfiledestinationoptions ();
Exportoptions. exportformattype = Getexportformattype (EXT );
Exportoptions. exportdestinationtype = Exportdestinationtype. diskfile;
Diskoptions. diskfilename = Filename + " . " + EXT;
Exportoptions. exportdestinationoptions = Diskoptions;
ReportDocument. Export (exportoptions );
}

The implementation of getexportformattype () is as follows:

Private Exportformattype getexportformattype ( String EXT)
{
Switch (EXT)
{
Case   " PDF " :
Return Exportformattype. portabledocformat;
Case   " RTF " :
Return Exportformattype. richtext;
Case   " Doc " :
Return Exportformattype. wordforwindows;
Case   " Xls " :
Return Exportformattype. Excel;
Case   " Html " :
Return Exportformattype. html32;
Default :
Return Exportformattype. noformat;
}
}

Getreportdocument () is a function that returns the reportdocument object of the report to be exported. You can implement this function at will.
Note that the filename format must be "C: \ crystalreport.

You can use this code template to export reports in five formats;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.