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

解决方案 »

  1.   

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

  2.   

            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控件 
      

  3.   

    调用微软Office的DLL,建立Excel对象,直接定义Format就可以了,还可以用Excel函数。
    .NET导出Excel高手,有什么问题可找我QQ104481987,[email protected]
      

  4.   

    看我的文章 应该能解决~哈哈
    http://blog.csdn.net/ranshouxu/article/details/8705529
      

  5.   

     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();
            }