zoukankan      html  css  js  c++  java
  • 用rdlc文件直接导出到excel或PDF

    private DataTable LoadSalesData()
            {
                // Load data from XML file.
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(@"c:\Reports\data.xml");
                return dataSet.Tables[0];
            }
           
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.reportViewer1.ProcessingMode = ProcessingMode.Local;
                this.reportViewer1.LocalReport.ReportPath = @"c:\Reports\Report1.rdl";
                reportViewer1.LocalReport.DataSources.Add(
                new ReportDataSource("Sales", LoadSalesData()));
                this.reportViewer1.RefreshReport();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Warning[] warnings;
                string[] streamids;
                string mimeType;
                string encoding;
                string extension;

                byte[] bytes = reportViewer1.LocalReport.Render(
                   "Excel", null, out mimeType, out encoding, out extension,
                   out streamids, out warnings);

                FileStream fs = new FileStream(@"c:\output.xls", FileMode.Create);
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();

                MessageBox.Show("Report exported to output.xls", "Info");

            }

    如果是BS模式,先保存在服务器上面,再从服务器上面下载下来

  • 相关阅读:
    js对象数组(JSON) 根据某个共同字段 分组
    一个 函数 用来转化esSearch 的range 条件
    关于 vuex 报错 Do not mutate vuex store state outside mutation handlers.
    android listview 重用view导致的选择混乱问题
    android SDK和ADT的更新
    Android中adb push和adb install的使用区别
    pycharm中添加扩展工具pylint
    su Authentication failure解决
    Putty以及adb网络调试
    有关android源码编译的几个问题
  • 原文地址:https://www.cnblogs.com/hubj/p/1318114.html
Copyright © 2011-2022 走看看