DataTable dtds = GetEncashmentExcel();//查数据的方法,返回一个DataTable,里面的值正确
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "";
this.EnableViewState = false;
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
Response.AddHeader("content-disposition", "attachment;filename=Encashment.xls");
DataGrid gd = new DataGrid();
gd.DataSource = dtds;
gd.DataBind();
gd.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();出现一个提示窗,很快就关掉了,时间大约不到1秒,看不到什么信息,然后就没任何反应了
解决方案 »
- sql 缓存问题
- 控制Gridview每行内的一些控件互斥
- (调用)大家开发ajax程序时用ajaxpro.dll还是用Atlas Framework
- ASP.NET 的Connection 连接问题,急,答对马上给分!在线等待!
- 在一个文本框中,双击总会出现以前输过的内容,怎么样将其去掉?
- .net 程序编译问题,请大家指教
- ASP.net 实例程序运行?急!
- 用程序创建表时如何让表名里有""(等符号啊?
- asp.net中的折叠菜单是怎样动态创建的?
- 急,POST到另一个地址的实现方法
- 纯HTML+WCF网站架构如何进行权限认证?
- 用DataContractJsonSerializer解析复杂json遇到的问题,请大家帮忙
我在VS05写导出在VS08中是可以用的,
检查其它问题...
public static void ToExcel(System.Web.UI.Control ctl, string filename)
{
//Response.Clear();
//Response.BufferOutput = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BufferOutput = true; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8).ToString());
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
ctl.RenderControl(hw);
//Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");//乱码
HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");//乱码
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}