• 水晶报表PDF出力方法


    使用前提条件:

    1,电脑安装水晶报表

    2,工程引用水晶报表相关的DLL

    全局变量声明

    1 public CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument1 = null;
    2 public CrystalDecisions.Shared.ExportOptions exportOpts = null;
    3 public CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfRtfWordFormatOptions = null;
    4 public CrystalDecisions.Shared.DiskFileDestinationOptions diskOpts = null;

    具体方法:

     1         #region PDF出力
     2         /// <summary>
     3         /// PDF出力
     4         /// </summary>
     5         /// <param name="rptName">crystalReport名</param>
     6         /// <param name="rptDataset">rptデータセット</param>
     7         /// <param name="rptObj">rptパラメータ</param>
     8         /// <param name="pdfDirectory">pdfDirectory</param>
     9         public void Out_PDFrpt(string rptName, object rptDataset, object[][] rptObj, string pdfDirectory)
    10         {
    11             // カレントパス保存
    12             string currentPass = Directory.GetCurrentDirectory();
    13 
    14             try
    15             {
    16                 //レポートの初期化
    17                 if (this.reportDocument1 != null)
    18                     this.reportDocument1.Dispose();
    19                 this.reportDocument1 = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    20                 this.reportDocument1.Load(rptName);
    21                 this.reportDocument1.SetDataSource(rptDataset);
    22                 if (rptObj != null)
    23                 {
    24                     foreach (object[] paraObj in rptObj)
    25                         this.reportDocument1.SetParameterValue((string)paraObj[0], paraObj[1]);
    26                 }
    27 
    28 
    29                 // PDF出力先取得
    30                 if (!Directory.Exists(pdfDirectory))
    31                 {
    32                     Directory.CreateDirectory(pdfDirectory);
    33                 }
    34 
    35                 Directory.SetCurrentDirectory(pdfDirectory);
    36 
    37                 // エクスポート設定
    38                 exportOpts = new CrystalDecisions.Shared.ExportOptions();
    39                 pdfRtfWordFormatOptions = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();
    40                 diskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    41                 exportOpts = reportDocument1.ExportOptions;
    42 
    43                 reportDocument1.ExportOptions.FormatOptions = pdfRtfWordFormatOptions;
    44                 reportDocument1.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
    45 
    46                 exportOpts.FormatOptions = pdfRtfWordFormatOptions;
    47                 exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
    48                 diskOpts.DiskFileName = DateTime.Now.ToString("yyyy-MM-dd-HHmmss")+".pdf";//出力PDF名称
    49                 exportOpts.DestinationOptions = diskOpts;
    50 
    51                 // PDF出力
    52                 this.reportDocument1.Export();
    53 
    54                 // カレントパス戻し
    55                 Directory.SetCurrentDirectory(currentPass);
    56             }
    57             catch (Exception ex)
    58             {
    59                 // カレントパス戻し
    60                 Directory.SetCurrentDirectory(currentPass);
    61                 throw ex;
    62             }
    63         }
    64         #endregion

     测试程序下载

    每天成就一小步,积累下来就是一大步。 转发本文请注明出处,谢谢您的阅读与分享!
  • 相关阅读:
    终端设备 tty,pty,pts 概念与文件描述符的联系
    Nginx – access_log格式及配置
    Nginx – rewrite 配置 URL重写及301跳转原理图
    nginx命令启动及选项
    nginx-web身份验证
    nginx_server_location对客户资源的辨别规则
    利用Session防止表单重复提交
    归并排序
    Cookie/Session的机制与安全
    HTTP Cookie Session
  • 原文地址:https://www.cnblogs.com/lixiaobin/p/PDF.html
Copyright © 2020-2023  润新知