首页 > 代码库 > ExtAspNet根据Grid导出Excel
ExtAspNet根据Grid导出Excel
protected void Button1_Click(object sender, EventArgs e) { Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls"); Response.ContentType = "application/excel"; Response.Write(GetGridTableHtml(Grid1)); Response.End(); } private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">"); sb.Append("<tr>"); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("<td>{0}</td>", column.HeaderText); } sb.Append("</tr>"); foreach (GridRow row in grid.Rows) { sb.Append("<tr>"); foreach (object value in row.Values) { string html = value.ToString(); sb.AppendFormat("<td>{0}</td>", html); } sb.Append("</tr>"); } sb.Append("</table>"); return sb.ToString(); }
ExtAspNet根据Grid导出Excel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。