【问题标题】:How to Export Crystal Report to Excel using CrystalReport Object and TableAdapter?如何使用 CrystalReport 对象和 TableAdapter 将 Crystal Report 导出到 Excel?
【发布时间】:2013-07-30 20:30:51
【问题描述】:

我正在使用数据集文件的 TableAdapter 方法从数据库中获取数据, 和Crysral 报表对象来创建报表而不是CrystalReport 文件本身。 (基本上我不想使用物理 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 文件。 请帮我解决这个问题...

【问题讨论】:

    标签: c# crystal-reports-2008


    【解决方案1】:

    试试这个:

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

    顺便说一句,不要忘记添加引用。

    【讨论】:

    • 对不起,我听不懂你的回答.. cClass 是什么?我在哪里设置我的数据源??
    • 抱歉,cClass 输入错误,请参阅我的更新。 rpt 代替了物理水晶报告文件(如您所说)。你必须首先做一个报告的对象。然后你会显示你的数据等等。当您要导出时,您将调用ExportToDisk() 方法,其中有两个parameters,第一个是您希望报告转换为的文件格式,第二个是我刚刚写的filepath如何将您的报告导出到 Excel(因为您的问题是关于此的)。
    • Yaaa.. 它正在工作.. 但是,它不需要声明 ReportClass Onject。对于这个rpt.ExportToDisk(ExportFormatType.Excel, "FilePath");,只有下面一行就足够了
    猜你喜欢
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多