我有一个复选框列表。如果我选择两个或多个值,那么 CheckBoxList SelectedValues 将作为参数一个一个地传递,我想为每个 SelectedValue 生成 PDF 格式的 Crystal Report,我想将所有 Crystal Report PDF 格式合并到一个 PDF 中格式。如何做到这一点? 到目前为止,我只生成了一个 PDF 格式的 Crystal Report。 在下面,我给出了有关如何生成 PDF 格式的 Crystal Report 的代码。
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
string[] str = conn.Split(';');
string server = str[0].Substring(str[0].IndexOf(" = ") + 3);
string database = str[1].Substring(str[1].IndexOf(" = ") + 3);
string userid = str[2].Substring(str[2].IndexOf(" = ") + 3);
string password = "Welc0me";//str[3].Substring(str[3].IndexOf(" = ") + 3);
rpt.Load(Server.MapPath(RepPath));
for (int i = 0; i < rpt.DataSourceConnections.Count; i++)
{
rpt.DataSourceConnections[i].SetConnection(server, database, userid, password);
}
// Here ReleaseID will be replaced by the CheckBoxList's SelectedValue
rpt.SetParameterValue(0, ReleaseID);
rpt.SetParameterValue(1, false);
rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,
HttpContext.Current.Response, true, "Docs Report");
但是上面的代码只是一次生成一个pdf报告。但我想将每个 CheckBoxList selectedvalue 作为参数传递。例如,如果我选择了三个值的意思,那么Crystal Report应该包含对应SelectedValue的三个Crystal Report一一对应。 如何将所有 PDF Crystal Report 合并到单个 Crystal Report 中。我必须解决这个问题。请帮助我。
最佳答案
Crystal Reports 旨在为每条记录生成一页。您只需设置一个包含多行数据的数据源,为您的报告设置该数据源并将其直接导出为 pdf(已经“合并”)。
首先,您必须使用您的数据创建一个数据源。例如,您可以使用 Visual Studio 设计器创建数据集。更多信息 here .
然后您必须为您的 Crystal Report 设置数据源。您可以使用 Crystal 设计器来完成。
然后在运行时,您只需使用与所有选中的复选框相关的数据填充 rpt,并将其导出为 pdf。在 .rpt 文件中,在与复选框相关的特定列上创建一个组,并在该组上设置“分页符”选项。这将生成一个包含所有记录的 Pdf 文件,每页 1 个。
这是一个示例代码:
using (var reportDocument = new ReportDocument())
{
var datasource = new Datasource { EnforceConstraints = false };
var adapter = new adoTableAdapter { Connection = ConfigurationManager.ConnectionStrings["ConnectionString"]) };
adapter.Fill(datasource.ado);
reportDocument.Load(RptPath);
reportDocument.SetDataSource(datasource);
PageMargins myMargins = reportDocument.PrintOptions.PageMargins;
myMargins.topMargin = Settings.Default.DefaultTopMargin;
myMargins.leftMargin = Settings.Default.DefaultLeftMargin;
reportDocument.PrintOptions.ApplyPageMargins(myMargins);
reportDocument.PrintOptions.PaperSize = PaperSize.PaperA5;
reportDocument.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
reportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
reportDocument.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
reportDocument.ExportOptions.DestinationOptions = new DiskFileDestinationOptions { DiskFileName = PdfFilename };
reportDocument.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();
reportDocument.Export();
}
在此代码中,dsEtiqueta 是 ADO 数据源,RptPath 是 *.rpt 报告文件的路径,pdf 文件名是使用 timeSpan 生成的。这是我在我的项目中需要的,但您可以根据您的需要随意调整它。
编辑:使用 VS 2010 的 CR 完成。
关于c# - 将两个或多个 Crystal Reports 合并为一个 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4898886/