ExtAspNet从DataTable里导出Excel

2021-07-11 01:06

阅读:537

标签:file   for   tostring   tab   send   net   osi   csharp   app   

 protected void btn_ToExcel_Click(object sender, EventArgs e)
    {
        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
        Response.ContentType = "application/excel";
        Response.Write(GetDataTableHtml((DataTable)ViewState["tt"]));
        Response.End();
    }


private string GetDataTableHtml(DataTable dt)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("
"); sb.Append(""); foreach (DataColumn column in dt.Columns) { sb.AppendFormat("", column.Caption); } sb.Append(""); foreach (DataRow row in dt.Rows) { sb.Append(""); for (int i = 0; i {0}", html); } sb.Append(""); } sb.Append("
{0}
"); return sb.ToString(); }

ExtAspNet从DataTable里导出Excel

标签:file   for   tostring   tab   send   net   osi   csharp   app   

原文地址:http://www.cnblogs.com/tlnshuju/p/7087333.html


评论


亲,登录后才可以留言!