Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 31st, 2007, 06:52 AM
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.
  #2 (permalink)  
Old October 4th, 2007, 01:00 AM
Registered User
 
Join Date: Oct 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shakti,

Hope u are doing fine.
I tried your code but it gives me the following error:
Server Error in '/Ultrabot7' Application.
--------------------------------------------------------------------------------

Method 'ISCREditableRTFExportFormatOptions_reserved5' on type 'CrystalDecisions.ReportAppServer.ReportDefModel.E ditableRTFExportFormatOptionsClass' from assembly 'CrystalDecisions.ReportAppServer.ReportDefModel, Version=11.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' is overriding a method that has been overridden.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Method 'ISCREditableRTFExportFormatOptions_reserved5' on type 'CrystalDecisions.ReportAppServer.ReportDefModel.E ditableRTFExportFormatOptionsClass' from assembly 'CrystalDecisions.ReportAppServer.ReportDefModel, Version=11.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' is overriding a method that has been overridden.

Source Error:


Line 57: ex.ExportDestinationOptions = destinationURL;
Line 58: ex.ExportFormatOptions = formatOptionEXCEL;
Line 59: mainReportDocument.Export(ex);
Line 60:
Line 61: }

.......

here is my code:
[[[[[[[[[[[[[[[[
mainReportPath = "../Reporting/Templates/UsersExportList.rpt";
                    mainReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocum ent();
                    mainReportDocument.Load(Server.MapPath(mainReportP ath));


                    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;
                    mainReportDocument.Export(ex);

]]]]]]]]]]]]]]]]]]]]]]

please help me where i am wrong.
Best Regards
Waseem

Quote:
quote:Originally posted by shakti_2505270
 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);


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Crystal Report To Excel mohithmohith VB.NET 1 July 12th, 2008 12:36 AM
Problem in exporting crystal report to excel. yasinirshad .NET Framework 1.x 0 June 11th, 2008 02:20 AM
problem in Exporting Crystal report to PDF cat_net Crystal Reports 0 October 3rd, 2005 11:49 PM
Exporting Crystal Report to PDF vishal.jayaswal .NET Web Services 0 December 30th, 2004 03:31 AM
Exporting Crystal Report 6 RPT file into PDF forma ravs1304 Crystal Reports 2 December 29th, 2004 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.