View Single Post
  #1 (permalink)  
Old August 31st, 2007, 06:52 AM
shakti_2505270 shakti_2505270 is offline
Authorized User
 
Join Date: Aug 2007
Location: mumbai, maharashtra, India.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code for Exporting Crystal Report to Excel or PDF

hi,
This is Shakti. I work as a Software Programmer.
I have seen that most of young programmers search for code to Export a Crystal Report to different Formats. So here their search comes to an end.



ReportDocument rd = new ReportDocument();
rd.SetDataSource(dt);
// Here i have considered that rd has been set with DataTable dt as its SetDataSource property.
// Hence forth the code to Export the Crystal Report to other formats starts.

ExportOptions ex = new ExportOptions();
DiskFileDestinationOptions destinationURL = new DiskFileDestinationOptions();
ExcelFormatOptions formatOptionEXCEL = new ExcelFormatOptions();
destinationURL.DiskFileName = "..//report.xls";
ex.ExportDestinationType = ExportDestinationType.DiskFile;
ex.ExportFormatType = ExportFormatType.Excel;
ex.ExportDestinationOptions = destinationURL;
ex.ExportFormatOptions = formatOptionEXCEL;
rd.Export(ex);

//The above code exports the Crystal Report to Excel
//Similarly you can export Crystal Reports to PDF

ExportOptions ex = new ExportOptions();
DiskFileDestinationOptions destinationURL = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions formatOptionPDF = new PdfRtfWordFormatOptions();
destinationURL.DiskFileName = "..//report.pdf";
ex.ExportDestinationType = ExportDestinationType.DiskFile;
ex.ExportFormatType = ExportFormatType.PortableDocFormat;
ex.ExportDestinationOptions = destinationURL;
ex.ExportFormatOptions = formatOptionPDF;
rd.Export(ex);
__________________
Software Programmer (ASP.NET),
Mumbai,
India.