如何使用CrystalReport对象和TableAdapter将Crystal Report导出到Excel?

时间:2013-07-30 11:58:40

标签: c# crystal-reports-2008

我正在使用数据集文件的TableAdapter方法从数据库中获取数据, 和Crysral报告对象来创建报告而不是CrystalReport文件本身。 (基本上我不想使用Physical CrystalReport文件)

这里是我的代码示例

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);
}

现在,我想使用此方法(CrystalReport对象)将报表导出到Excel文件。 请帮我解决这个问题...

1 个答案:

答案 0 :(得分:2)

试试这个:

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

BTW不要忘记添加引用。