zoukankan      html  css  js  c++  java
  • 水晶报表导出数据并实现打印


    要在里一个页面上进行操作


    ReportDocument rdocument = new ReportDocument();

        //公用打印方法
        ExportCrystalL ExCrystal = new ExportCrystalL();

        User u = new User();

        #region 加载页面
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //加载报表
                LoadReport();
            }
        }

        /// <summary>
        /// 加载报表
        /// </summary>
        private void LoadReport()
        {
            //设置报表的数据信息
            GetReportDataSource();
            string FilePath = Request.PhysicalApplicationPath + "temp\\";
            string FileName = "水晶报表练习" + DateTime.Now.ToShortDateString();

            //导出数据
            ExCrystal.Export(rdocument, FilePath, FileName, "xls");
        }

        /// <summary>
        /// 设置报表的数据信息
        /// </summary>
        private void GetReportDataSource()
        {
            //取得数据
            DataSet ds = u.GetData("");

            if (ds != null && ds.Tables[0].Rows.Count != 0)
            {
                //加载水晶报表的模板
                rdocument.Load(Server.MapPath("../Report/MyReport.rpt"));

                //设置报表的数据源
                rdocument.SetDataSource(ds.Tables[0]);
            }

            //绑定
            this.CrystalReportViewer1.ReportSource = rdocument;
            this.CrystalReportViewer1.DataBind();
        }
        #endregion

  • 相关阅读:
    C++的Socket的使用源码
    一些程序技术简介
    VMware安装步骤既常见问题
    操作系统和环境准备
    第一章-硬件组成
    python之面向对象
    指向方法之委托(一)
    Django之URL控制器(路由层)
    python之字符编码(四)
    python之字符编码(三)
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1763519.html
Copyright © 2011-2022 走看看