Gridview 导出 Excel2010? Gridview 导出 Excel2010 ,不是乱码就是资源版本的问题,请教高手,如何避免上述错误呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 2010?还没用过乱码 你就设置一下编码看看Response.Charset="GB2312"; Excel2010采用了不同的格式,标准的格式你需要采用Open XML、OpenXML或OOXML的格式生成才是最标准的xlsx文件,参见http://msdn.microsoft.com/en-us/office/bb265236另外,你也可以采用兼容的xml格式,可以设置样式、合并行列等参见http://dotnet.aspx.cc/file/Export-Gridview-To-Excel-With-Multi-Sheet.aspx 搞定了.. string style = @"<style> .text { mso-number-format:\@; } </script> "; string s = this.ddlYWName.Text; Response.Clear(); //获取或设置一个值,该值指示是否缓冲输出,并在完成处理整个响应之后将其发送 Response.Buffer = true; //获取或设置输出流的HTTP字符集 Response.Charset = "GB2312"; // filename = System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.GetEncoding("GB2312 ")); //将HTTP头添加到输出流 Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(s + ".xls", Encoding.UTF8).ToString()); //获取或设置输出流的HTTP字符集 Response.ContentEncoding = System.Text.Encoding.UTF7; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //获取或设置输出流的HTTP MIME类型 // Response.ContentType = "application/ms-excel"; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter onstringwriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter onhtmltextwriter = new System.Web.UI.HtmlTextWriter(onstringwriter); StringWriter sw = new StringWriter(); Response.Write(style); HtmlTextWriter htw = new HtmlTextWriter(sw); this.gdvNonBindData.RenderControl(htw); string html = sw.ToString().Trim(); Response.Output.Write(html); Response.Flush(); Response.End(); public override void VerifyRenderingInServerForm(Control control) { //base.VerifyRenderingInServerForm(control); } 怎么把数据库的内容在TreeView上显示~~~~ asp.net分离字符串C# 自定义类型的调用问题请教 为什么会那么慢? Asp.net中的Forms认证如何对跨域的AD用户进行验证? 在javascript中如何获得日期控件的值? 请教页面问题 asp.net 点击按钮关闭窗口并刷新父页面 DataGrid修改列,如何在点击修改时弹出页面后,不刷新原页面? 问:怎么把aspx网页显示的内容copy到htm页面上,并把htm文件保存到硬盘? ASP.NET或者JS如何打开第三方cookie 急-Repeater中嵌入了RadioButtonList
还没用过
乱码 你就设置一下编码看看Response.Charset="GB2312";
参见
http://msdn.microsoft.com/en-us/office/bb265236另外,你也可以采用兼容的xml格式,可以设置样式、合并行列等
参见
http://dotnet.aspx.cc/file/Export-Gridview-To-Excel-With-Multi-Sheet.aspx
string style = @"<style> .text { mso-number-format:\@; } </script> ";
string s = this.ddlYWName.Text;
Response.Clear();
//获取或设置一个值,该值指示是否缓冲输出,并在完成处理整个响应之后将其发送
Response.Buffer = true;
//获取或设置输出流的HTTP字符集
Response.Charset = "GB2312";
// filename = System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.GetEncoding("GB2312 "));
//将HTTP头添加到输出流
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(s + ".xls", Encoding.UTF8).ToString());
//获取或设置输出流的HTTP字符集
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//获取或设置输出流的HTTP MIME类型
// Response.ContentType = "application/ms-excel"; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter onstringwriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter onhtmltextwriter = new System.Web.UI.HtmlTextWriter(onstringwriter);
StringWriter sw = new StringWriter();
Response.Write(style);
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.gdvNonBindData.RenderControl(htw);
string html = sw.ToString().Trim();
Response.Output.Write(html);
Response.Flush();
Response.End(); public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}