【问题标题】:Crystal Reports directly download into pdf C#水晶报表直接下载成pdf C#
【发布时间】:2017-01-12 07:15:11
【问题描述】:

我想直接将水晶报告下载到 pdf 中一起查看 CommonReportViewer.aspx 页面,我正在本地服务器上运行我的项目,源 MYPROJECT 和 (.rpt) 报告在 D:\MYPROJECT\Reporting\Deposit\报告。我在 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();
            }

        }
    }

【问题讨论】:

    标签: c# asp.net pdf crystal-reports crystal-reports-2010


    【解决方案1】:

    应进行一些更改以将其导出为 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
                {
    
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2015-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 2020-08-05
      • 1970-01-01
      相关资源
      最近更新 更多