gridview 保存到 excel c# .net gridview乱码excel.netwebform 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://bbs.csdn.net/topics/390796988http://bbs.csdn.net/topics/390780207发帖两次,未解决....... 试试 下边的代码GridView gv = new GridView(); gv.DataSource = dtError; gv.DataBind(); gv.Attributes.Add("style", "vnd.ms-excel.numberformat:@"); HttpResponse hResponse = this.Response; string fileName1 = "新员工格式验证错误统计" + DateTime.Now.ToString("yyyyMMdd"); hResponse.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName1, System.Text.Encoding.UTF8) + ".xls"); hResponse.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); hResponse.ContentType = "application/ms-excel"; this.EnableViewState = false; StringWriter tw = new StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); gv.RenderControl(hw); hResponse.Write(tw); hResponse.End(); 你的方法我试过的呀。http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢? 你安装的win7是ghost 版的吧,如果是,里面集成是的office2007版本的,你原来是office2003版本,肯定打不开的。建议你把office2007删除,重新安装office2003.试试看。 你的方法我试过的呀。http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢?弹出下载框是什么样子的?、要用IE下载 是 win7 Ghost 版的 公司现在都是 office 2007 的 (总不能全部都要安装2003吧) 之前是 office 2003 就没有问题 ,有啥好的办法可以解决吗? 你的方法我试过的呀。http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢?弹出下载框是什么样子的?、要用IE下载弹出框如下保存后 打开的样子 如下:http://bbs.csdn.net/topics/390780207 public static void DGToExcel(Control ctl, string fileName) { HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+fileName); HttpContext.Current.Response.Charset = ""; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; ctl.Page.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); }修改一下编码方式解决乱码问题 让你测试是不是office版本引起的问题无语了 BOM 物料清单 ? 这个有啥用呀? 不懂耶.... 你导出的是2003格式的win7上默认的是office2007,要打开2003的文档,需要安装office2007兼容性组件 BOM 物料清单 ? 这个有啥用呀? 不懂耶....BOM = ByteOrderMarking 求牛人回答!!C/S下DataGridView绑定数据的问题!!! 关于Timer每隔一秒打印个数字 winform 动态添加节点并将节点保存到xml中? 编码问题,iso-8859-1,utf-8,unicode变量转换 求教!!解决乱码问题 怎么样重写DataGrid,建自已的表格控件 在给DataSet中添加Relation的时候的问题 写了个小程序,大家帮我找BUG哦 有人有关于正则表达式的教程啊? 如何编程改变richtextBox中文字的大小 winfrom 程序 发布 之后是不是不带配置文件的??? wpf combobox 多选
http://bbs.csdn.net/topics/390780207
发帖两次,未解决.......
gv.DataSource = dtError;
gv.DataBind();
gv.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
HttpResponse hResponse = this.Response;
string fileName1 = "新员工格式验证错误统计" + DateTime.Now.ToString("yyyyMMdd");
hResponse.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName1, System.Text.Encoding.UTF8) + ".xls");
hResponse.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
hResponse.ContentType = "application/ms-excel";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
gv.RenderControl(hw);
hResponse.Write(tw);
hResponse.End();
http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢?
http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢?
弹出下载框是什么样子的?、要用IE下载
有啥好的办法可以解决吗?
http://bbs.csdn.net/topics/390796988 见 3 楼是不是不兼容的缘故呢?
弹出下载框是什么样子的?、要用IE下载
弹出框如下
保存后 打开的样子 如下:
http://bbs.csdn.net/topics/390780207
public static void DGToExcel(Control ctl, string fileName)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+fileName);
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
ctl.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}修改一下编码方式解决乱码问题
win7上默认的是office2007,要打开2003的文档,需要安装office2007兼容性组件