Print and export formats of Crystal Reports

Source: Internet
Author: User
In ASP. NET, the crystal report does not provide the report export and printing functions as in Windows form. We need to add code to control it by ourselves. Here is a demo:

Myreport reportdoc = new myreport (); // table name
Private void btnexport_click (Object sender, system. eventargs E)
Crystaldecisions. Shared. diskfiledestinationoptions diskopts = new crystaldecisions. Shared. diskfiledestinationoptions ();
Reportdoc. exportoptions. exportdestinationtype = crystaldecisions. Shared. exportdestinationtype. diskfile;
Switch (dropdownlist1.selecteditem. Text)
Case "Rich Text (RTF )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. richtext;
Diskopts. diskfilename = "D: // demo. rtf ";
Case "Portable Document (PDF )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. portabledocformat;
Diskopts. diskfilename = "D: // demots ";
Case "MS Word (DOC )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. wordforwindows;
Diskopts. diskfilename = "D: // demo.doc ";
Case "MS Excel (xls )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. Excel;
Diskopts. diskfilename = "D: // demo.xls ";
Reportdoc. exportoptions. destinationoptions = diskopts;
Reportdoc. Export ();

Private void btnprint_click (Object sender, system. eventargs E)
String strprintername; // specify the printer name
Strprintername = @ "Canon Bubble-jet BJC-210SP ";
Pagemargins margins; // sets the print margin.
Margins = reportdoc. printoptions. pagemargins;
Margins. bottommargin = 250;
Margins. leftmargin = 350;
Margins. rightmargin = 350;
Margins. topmargin = 450;
Reportdoc. printoptions. applypagemargins (margins );
Reportdoc. printoptions. printername = strprintername; // The Name Of The application printer.
// Print the report. startpagen and endpagen
// If the parameter is set to 0, all pages are printed.
Reportdoc. printtoprinter (1, false, 0, 0 );


Related Article

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: 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.