c#导出Excel文件,转换为可读模式

来源:互联网 发布:华为网络盒子支持4k吗 编辑:程序博客网 时间:2024/06/05 10:54
    /// <summary>    /// 导出Excel文件,转换为可读模式    /// </summary> //转载请注明来自 http://www.shang11.com    public static void DataTable2Excel(System.Data.DataTable dtData)    {        DataGrid dgExport = null;        HttpContext curContext = HttpContext.Current;        StringWriter strWriter = null;        HtmlTextWriter htmlWriter = null;        if (dtData != null)        {            curContext.Response.ContentType = "application/vnd.ms-excel";            curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;            curContext.Response.Charset = "";            strWriter = new StringWriter();            htmlWriter = new HtmlTextWriter(strWriter);            dgExport = new DataGrid();            dgExport.DataSource = dtData.DefaultView;            dgExport.AllowPaging = false;            dgExport.DataBind();            dgExport.RenderControl(htmlWriter);            curContext.Response.Write(strWriter.ToString());            curContext.Response.End();        }    }

0 0
原创粉丝点击