日期:2014-05-17  浏览次数:20495 次

asp导出复杂excel报表的问题!

想要导出这种格式的excel文件如何实现?

------解决方案--------------------
拼接HTML,然后返回的时候在http头信息中指定
ContentType: application/ms-excel;
还有
Content-Disposition:attachment;filename=file.xls

------解决方案--------------------
        public void DGToExcel(System.Web.UI.Control ctl)
        {
            mytable.Columns[12].Visible = false;
            mytable.Columns[13].Visible = true;
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=MemberDetail.xls");
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            ctl.Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }

调用DGToExcel(mytable); //直接导出datagrid控件