Ext.NET 导出Excel时不认列 http://www.cnblogs.com/sanshi/archive/2009/08/23/1552533.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你试试 将GridPanel中的数据现在添加到一个DataTable里面 for (int i = 0; i < this.GridPanel.Columns.Count; i++) { //将表头信息添加到DataTable表头 dt2.Columns.Add(this.GridPanel.Columns[i].HeaderText); } for (int i = 0; i < dt.Rows.Count; i++) { dt2.Rows.Add(dt.Rows[i].ItemArray); //添加数据行 } ToExcel(dt2);然后在public void ToExcel(DataTable dt) { DataGrid dgExcel = new DataGrid(); dgExcel.DataSource = dt; dgExcel.DataBind(); HttpContext.Current.Response.Charset = "GB2312"; string fileName = HttpUtility.UrlEncode(Guid.NewGuid().ToString(), System.Text.Encoding.UTF8); string str = "attachment;filename=" + fileName + ".xls"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.AppendHeader("content-disposition", str); StringWriter sw = new StringWriter(); HtmlTextWriter htmTextWriter = new HtmlTextWriter(sw); dgExcel.RenderControl(htmTextWriter); HttpContext.Current.Response.Write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); string style = "<style>td{mso-number-format:\"\\@\";}</style>";//防止导出excel时将以0开头的全数字数据的0去掉 HttpContext.Current.Response.Write(style); HttpContext.Current.Response.Write("</head><body>"); HttpContext.Current.Response.Write(sw); HttpContext.Current.Response.Write("</body></html>"); HttpContext.Current.Response.End(); } 一段代码求解~。~谢谢 急,在线等 .net大型网站应该如何架构才合理? 求能在客户端验证文件大小的方法 #求个正则,高手请进# 求问关于用户控件中的事件 在线等,首次进入跳出弹窗!IsPostBack 发布网站时报web.config有错 如何获得abc(1231234)中的括号内的字符串 如下代码行为什么错 (用***标注),在线等。 我在Win7 IIS6下发布.NET 4.0的网站,已经注册好,但仍然有以下错误,这是什么原因呢 如何asp.net电商网站让数字分页保持搜索条件过滤。
for (int i = 0; i < this.GridPanel.Columns.Count; i++)
{
//将表头信息添加到DataTable表头
dt2.Columns.Add(this.GridPanel.Columns[i].HeaderText); }
for (int i = 0; i < dt.Rows.Count; i++)
{
dt2.Rows.Add(dt.Rows[i].ItemArray); //添加数据行
}
ToExcel(dt2);
然后在
public void ToExcel(DataTable dt)
{
DataGrid dgExcel = new DataGrid();
dgExcel.DataSource = dt;
dgExcel.DataBind();
HttpContext.Current.Response.Charset = "GB2312";
string fileName = HttpUtility.UrlEncode(Guid.NewGuid().ToString(), System.Text.Encoding.UTF8);
string str = "attachment;filename=" + fileName + ".xls";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("content-disposition", str);
StringWriter sw = new StringWriter();
HtmlTextWriter htmTextWriter = new HtmlTextWriter(sw);
dgExcel.RenderControl(htmTextWriter);
HttpContext.Current.Response.Write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
string style = "<style>td{mso-number-format:\"\\@\";}</style>";//防止导出excel时将以0开头的全数字数据的0去掉
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.Write("</head><body>");
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.Write("</body></html>");
HttpContext.Current.Response.End();
}