[英]Crystal Reports directly download into pdf C#
我想将Crystal报表直接下载到pdf中,一起在CommonReportViewer.aspx页中查看,我正在使用源MYPROJECT在本地服务器上运行我的项目,并在D:\\ MYPROJECT \\ Reporting \\ Deposit \\ Reports上运行(.rpt) 报告 。 我在Stackoverflow尝试了不同的解决方案,即ExportToDisk,ExportOptions等 ,但无法获得解决方案。 就我而言,要查看银行报告,我通过表格提供了报告参数,最后到达了报告参数并显示了报告。 我的问题是,如何打印多页报告,我该如何直接以pdf格式下载该报告。
CommonReportViewer.aspx.cs :
public partial class CommonReportViewer : System.Web.UI.Page
{
ReportDocument mainDoc = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
try
{
CrystalReport report = new CrystalReport();
report = (CrystalReport)Session["NLK_REPORT"];
DateTime t1 = DateTime.Now;
mainDoc.Load(report.ReportFilePath, OpenReportMethod.OpenReportByDefault);
mainDoc.RecordSelectionFormula = report.SelectionCriteria;
mainDoc.Refresh();
string server = "NLKNEWDB";
string userID = report.UserID;
string password = report.Password;
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in report.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue);
}
foreach (SubReport sr in report.SubReportList)
{
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in sr.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue, sr.SubReportName);
}
}
mainDoc.SetDatabaseLogon(userID, password, server, "");
this.crptViewer.ReportSource = mainDoc;
mainDoc.DataSourceConnections.Clear();
}
finally
{
}
}
void ApplyLogonInfo(ReportDocument report, string server, string userID, string password)
{
TableLogOnInfo info = new TableLogOnInfo();
ConnectionInfo cinfo = new ConnectionInfo();
cinfo.ServerName = server;
cinfo.UserID = userID;
cinfo.Password = password;
info.ConnectionInfo = cinfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
{
tbl.ApplyLogOnInfo(info);
}
}
private void Page_Unload(object sender, System.EventArgs e)
{
if (mainDoc != null)
{
mainDoc.Close();
mainDoc.Dispose();
}
}
}
应进行一些更改以将其导出为PDF格式。 页面加载后,将Page_Load方法更改为。
protected void Page_Load(object sender, EventArgs e)
{
try
{
CrystalReport report = new CrystalReport();
report = (CrystalReport)Session["NLK_REPORT"];
DateTime t1 = DateTime.Now;
mainDoc.Load(report.ReportFilePath, OpenReportMethod.OpenReportByDefault);
mainDoc.RecordSelectionFormula = report.SelectionCriteria;
mainDoc.Refresh();
string server = "NLKNEWDB";
string userID = report.UserID;
string password = report.Password;
string empId = null;
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in report.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue);
if (param.ParamName == "P_EMPLOYER_ID")
{
empId = param.ParamValue.ToString();
}
}
foreach (SubReport sr in report.SubReportList)
{
this.ApplyLogonInfo(mainDoc, server, userID, password);
foreach (ReportParameter param in sr.ParamList)
{
mainDoc.SetParameterValue(param.ParamName, param.ParamValue, sr.SubReportName);
}
}
mainDoc.SetDatabaseLogon(userID, password, server, "");
mainDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, empId);
this.crptViewer.ReportSource = mainDoc;
mainDoc.DataSourceConnections.Clear();
}
finally
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.