Asp.Net WebForm Rdlc 报表的使用之导出Excel

实现代码

        /// <summary>
        /// 导出excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            //绑定数据
            SetReportViewer();
            // Variables
            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;
            byte[] bytes = _ReportViewer.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
            // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            String filename = HttpUtility.UrlEncode("报表导出", Encoding.UTF8);
            Response.AddHeader("content-disposition", "attachment; filename=" + filename + "." + extension);
            Response.BinaryWrite(bytes); // create the file
            Response.Flush(); // send it to the client to download
        }

 

上一篇:C#-禁用折线图类别组按字母顺序排序


下一篇:CodeGo.net>如何在某些条件下(本地报表)在tablix中指定单元格的文本颜色?