如何在一个应用程序中使用多个.rpt文件(水晶报告)

本文关键字:rpt 文件 报告 水晶 应用程序 一个 | 更新日期: 2023-09-27 18:14:18

有人知道如何在一个应用程序中使用多个.rpt文件(水晶报告)吗?我需要生成报告,并直接保存到。pdf,但我不知道如何做到这一点。当我使用单个。rpt文件时,我设法做到了,但我不确定如何使用多个。rpt文件生成报告。有人能帮我一下吗?

我的编码:

ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("C:''rptBilling.rpt");
crConnectionInfo.ServerName = "ServerName";
crConnectionInfo.DatabaseName = "DatabaseName";
crConnectionInfo.UserID = "userID";
crConnectionInfo.Password = "Password";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
cryRpt.SetParameterValue("@CollectionStartDate", "2011/09/14");
cryRpt.SetParameterValue("@CollectionEndDate", "2011/09/29");
cryRpt.SetParameterValue("@SpokeCode", "14");//country code
cryRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1
cryRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1
cryRpt.SetParameterValue("@UploadStartDate", "2011/09/23");
cryRpt.SetParameterValue("@UploadEndDate", "2011/09/23");
cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:''1.pdf");

如何在一个应用程序中使用多个.rpt文件(水晶报告)

如果您指的是单独的pdf文件,那么您可以使用cryRpt.Load()重新加载新的rpt。请确保在新参数上清除参数和SetParameterValue。

编辑:我不能发表评论,因为我没有足够的点,但我从来没有使用过水晶报告功能,但我假设你可以保持相同的变量cryRpt,一旦你加载你的第一个pdf,你可以通过调用load()再次重用cryRpt,并通过相同的步骤,因为你已经做了,但使用新的变量,如果需要。如果它不允许多个脚本,您可以丢弃并初始化一个新脚本。我可能会误解你在寻找什么,因为我假设你想要两个单独的pdf文件。