导出功能的问题 asp.net 中到处功能,有的时候是将Gridview导出Excel,有的时候导出的是asp页面,这是为啥?我的Excel是2003的,跟版本问题有关吗? 代码是正确的,只有我遇到这样的问题,其他人没有,很奇怪,有没有人遇到这样的问题,求解!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也遇到过!和Excel版本没有关系!public static void ToExcel(GridView ctl, string FileName) { for (int i = 0; i < ctl.Columns.Count; i++) //设置每个单元格 { ctl.Columns[i].ItemStyle.HorizontalAlign = HorizontalAlign.Left; for (int j = 0; j < ctl.Rows.Count; j++) { ctl.Rows[j].Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@;"); } } HttpContext.Current.Response.Charset = "GBK"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName); ctl.Page.EnableViewState = false; System.IO.StringWriter tw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); ctl.RenderControl(hw); string style = @"<style> .text { mso-number-format:\@; } </style> "; HttpContext.Current.Response.Write(style); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); }页面直接调用就可以了 门户网的首页怎么做?在线等 关于DAL引用MODEL层的问题 为什么改成这样了还是不行呢,还是说INSERT语句错误? 怎么获得嵌套的datalist内的控件? aspx页面无法响应问题,怀疑是.net的bug. 在两台电脑中的程序相同,运行结果不同是怎么回事 服务器控件button如何在指定框架中打开网页?急须,在线等…… 求datagrid操作数据的解决方案? 读取excel表数据找不到可安装的ISM asp.net 如何主动调用微信企业号接口,发送文本消息 mvc3 Razor页面ajax问题 如何用DropDownList做查询
{
for (int i = 0; i < ctl.Columns.Count; i++) //设置每个单元格
{
ctl.Columns[i].ItemStyle.HorizontalAlign = HorizontalAlign.Left;
for (int j = 0; j < ctl.Rows.Count; j++)
{
ctl.Rows[j].Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
}
} HttpContext.Current.Response.Charset = "GBK";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
string style = @"<style> .text { mso-number-format:\@; } </style> ";
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
页面直接调用就可以了