Solved

convert crystal reports to excel in asp.net with c#

Posted on 2009-05-12
15
2,351 Views
Last Modified: 2012-05-06
convert crystal reports to excel in asp.net with c#
0
Comment
Question by:tatchis1
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 24366228
What version of Crystal?

You can export a report to Excel.  Are you viewing the report?

mlmcc
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24367427
This is VB, but you get the picture

    Dim rpt As New CRAXDRT.Report

    Set rpt = xtal.OpenReport(ReportFile)

    rpt.ReadRecords

    rpt.ExportOptions.DestinationType = crEDTDiskFile

    rpt.ExportOptions.FormatType = crEFTExcelDataOnly

    rpt.ExportOptions.ExcelExportImagesInDataOnly = True

    rpt.ExportOptions.ExcelMaintainRelativeObjectPosition = True

    rpt.ExportOptions.ExcelUseFormatInDataOnly = True

    rpt.ExportOptions.ExcelMaintainColumnAlignment = True

    rpt.ExportOptions.DiskFileName = C:\Blah.xls"

    rpt.Export False

Open in new window

0
 

Author Comment

by:tatchis1
ID: 24367856
Crystal Reports XI Release 2

             string xcelFile = "Report.csv";

            ExportOptions exportOpts = cryRpt.ExportOptions;

            exportOpts.ExportFormatType = ExportFormatType.Excel;
            exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
            exportOpts.DestinationOptions = new DiskFileDestinationOptions();
            // Set the disk file options.
            DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

            ((DiskFileDestinationOptions)cryRpt.ExportOptions.DestinationOptions).DiskFileName =              
                                                                  Server.MapPath(xcelFile);

            cryRpt.Export();

I'm getting a report but not totally in excell format.
0
 
LVL 16

Expert Comment

by:JohnBPrice
ID: 24367955
Crystal has both Excel and ExcelDataOnly, and a number of different options to configure for each regarding what gets exported, how it gets lined up, etc.  You can play with those options in Crystal to figure out which are best for your need, and then adjust your code to match.  I've never been able to get Excel exports to look exactly like the report the way pdf exports do.
0
 
LVL 1

Expert Comment

by:usmanr
ID: 24368173
you can also try this code.            

ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

            ExportOptions CrExportOptions = null;
            DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

            ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();

            CrDiskFileDestinationOptions.DiskFileName = "c:\crystalExport.xls";
            CrExportOptions = cryRpt.ExportOptions;

            CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            CrExportOptions.ExportFormatType = ExportFormatType.Excel;
            CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
            CrExportOptions.FormatOptions = CrFormatTypeOptions;
           
            cryRpt.Export();
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24368645
What do you mean not toally in Excel format?
Crystal does a basic WYSIWYG export to Excel and may merge cells and have other issues

Check these documents on how to format the report for export to Excel.
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10d3ba69-951e-2b10-3093-e3cf287a57c9

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/20c9c239-7b64-2b10-4ab3-b59d52ed35de

mlmcc
0
 

Author Comment

by:tatchis1
ID: 24386522
I have attach the Crystal Report that I converted to excel, it not in a  excel format
Assets-have-been-Inspected-Repor.xls
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 100

Expert Comment

by:mlmcc
ID: 24387236
It opens in Excel so it is in Excel format.

Do you mean the merged cells, if so that is the way Crystal exports and it cannot be changed.
The articles I referenced above provide information for building/formatting the report so it exports as a "true" Excel file.

The other option would be to try the DATA ONLY export optiion and see if that gives you a better result.

mlmcc
0
 

Author Comment

by:tatchis1
ID: 24398492
The only other problem that I encounter is when the Web Application invoke the Crystal Report as a pdf. The pdf file is saved to the hard drive, how do I stop this from happening.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24398832
How are you doing the export?

mlmcc
0
 

Author Comment

by:tatchis1
ID: 24399043
I'm using the code listed below to do my export to pdf

ExportOptions exportOpts = cryRpt.ExportOptions;

            exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
            exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
            exportOpts.DestinationOptions = new DiskFileDestinationOptions();
            // Set the disk file options.
            DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

            ((DiskFileDestinationOptions)cryRpt.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath(pdfFile);

            cryRpt.Export();

            Response.WriteFile(pdfFile);
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 24399491
I believe it is

exportOpts.ExportDestinationType = ExportDestinationType.Application

mlmcc
0
 

Author Comment

by:tatchis1
ID: 24400286
I spoke too soon this will work when exporting to excel but not to a pdf

 Excel
---------
            exportOpts.ExportFormatType = ExportFormatType.ExcelRecord;
            exportOpts.ExportDestinationType = ExportDestinationType.NoDestination;
            exportOpts.DestinationOptions = new DiskFileDestinationOptions();

            // Set the disk file options.
            DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

            ((DiskFileDestinationOptions)cryRpt.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath(xcelFile);

            cryRpt.Export();
            Response.Redirect(xcelFile);

PDF
------

ExportOptions exportOpts = cryRpt.ExportOptions;

            exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
            exportOpts.ExportDestinationType = ExportDestinationType.NoDestination;
            exportOpts.DestinationOptions = new DiskFileDestinationOptions();
            // Set the disk file options.
            DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

            ((DiskFileDestinationOptions)cryRpt.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath(pdfFile);

            cryRpt.Export();

            Response.WriteFile(pdfFile);
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24400346
Do you still need help?

mlmcc
0
 

Author Comment

by:tatchis1
ID: 24402409
yes, I still need help with the conversion of Crystal Report to a pdf without creating a disk file.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now