Dhaval Ptl
Dhaval Ptl

Reputation: 494

How to Export Crystal Report to Excel using CrystalReport Object and TableAdapter?

I am using TableAdapter method of dataset file to get data from database, and Crysral report object to create report instead of CrystalReport file itself. (Basically I don't want to use Physical CrystalReport File)

Here, sample of my Code

DataTable dtRpt = new DataTable();
CrystalReportViewer crv = new CrystalReportViewer();
using (uspRptComplainReceiptTableAdapter _adpSales = new uspRptComplainReceiptTableAdapter())
{
    dtRpt = _adpSales.GetData(Convert.ToByte(bolObj.CompId), bolObj.ComplainId) as DataTable;
    if (dtRpt != null && dtRpt.Rows.Count > 0)
    {
         crptComplainReceipt rpt1 = new crptComplainReceipt();
         rpt1.SetDataSource(dtRpt);
         crv.ReportSource = rpt1;
         crv.PrintReport();
    }
    else
         MessageBox.Show("Record not found.", "Report", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Now, I want to Export my report to Excel File using this method (CrystalReport Object). Please, help me for this problem...

Upvotes: 3

Views: 10736

Answers (1)

Mehrdad Kamelzadeh
Mehrdad Kamelzadeh

Reputation: 1784

Try This:

 CrystalDecisions.CrystalReports.Engine.ReportClass rpt=new ReportClass();
 rpt.ExportToDisk(ExportFormatType.Excel, "FilePath");

BTW do not forget to add the references.

Upvotes: 3

Related Questions