asp.net Crystal Report printing and exporting format

Source: Internet
Author: User
Tags format table name
Asp.net| Printing | Crystal report in asp.net The Crystal Report does not provide the export and printing functionality of the report as it does in Windows Form, it requires us to add code to control, and here's a demo:





Export:


myreport Reportdoc = new Myreport ()//table 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";


break;


case "Portable Document (PDF)":


ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;


diskopts.diskfilename = "D:\\demo.pdf";


break;


case "MS Word (DOC)":


ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;


diskopts.diskfilename = "D:\\demo.doc";


break;


case "MS Excel (XLS)":


ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;


diskopts.diskfilename = "D:\\demo.xls";


break;


Default:


break;


   }


ReportDoc.ExportOptions.DestinationOptions = diskopts;


Reportdoc.export ();


  }





Print:


private void Btnprint_click (object sender, System.EventArgs e)


  {


string Strprintername; Specify Printer name


strprintername = @ "Canon bubble-jet bjc-210sp";


pagemargins margins; Set up print margins


margins = ReportDoc.PrintOptions.PageMargins;


Margins.bottommargin = 250;


margins.leftmargin = 350;


margins.rightmargin = 350;


margins.topmargin = 450;


ReportDoc.PrintOptions.ApplyPageMargins (margins);


ReportDoc.PrintOptions.PrinterName = strprintername; Apply Printer Name


//print reports. Startpagen and Endpagen

The
//parameter setting of 0 indicates that 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: 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.