我有一个复选框列表。如果我选择两个或多个值,则 CheckBoxList SelectedValues 将作为参数一一传递,并且我想为每个 SelectedValue 生成 PDF 格式的 Crystal Report,并且我想将所有 Crystal Report PDF 格式合并为单个 PDF格式。如何实现这一目标?
到目前为止,我只生成了一个 PDF 格式的 Crystal Report。
在下面,我给出了关于如何生成 PDF 格式的水晶报表的代码。
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 选定值作为参数传递。例如,如果我选择了三个值,那么Crystal Report应该一一包含所有三个Crystal Report对应的SelectedValue。
如何将所有 PDF Crystal Report 合并为单个 Crystal Report。我必须解决这个问题。请帮我。
水晶报表是meant每条记录生成一页。您只需设置一个包含多行数据的数据源,为您的报告设置该数据源并将其直接导出为 pdf(已“合并”)。
首先,您必须使用您的数据创建一个数据源。例如,您可以使用 Visual Studio 设计器创建数据集。更多信息here.
然后您必须设置水晶报表的数据源。您可以使用 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 完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)