首页 » .NET » ASP.NET 将表格导到Excel实例

ASP.NET 将表格导到Excel实例

原文 http://blog.csdn.net/qiufengwuxiu/article/details/79015099

2018-01-10 02:00:29阅读(544)

前端:页面单独显示数据表


后台调用下面这个方法即可:

private void GetDC()

    {
        Response.Clear();
        Response.Buffer = true;

        //Response.Charset = "gb2312";


        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Term+"评议表" + System.DateTime.Today.Month + System.DateTime.Today.Day + ".xls", Encoding.UTF8).ToString());

        //Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.Charset="gb2312";
        Response.ContentType = "application/ms-Excel";

        //this.EnableViewState = false;

        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

        this.pn.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());

        Response.End();
    }

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹