asp.net+dbgrid导出excel后,excel文件不能读取问题
在网络由很多dbgrid导出excel的文章,我使用如下方式导出excel文件
打开此文件,始终提示不能读取excel文件,请大侠指点,我用的excel2003
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer= true;
Response.Charset="utf-8";
Response.AppendHeader("Content-Disposition","attachment;filename=test.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/ms-excel";
this.EnableViewState =false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
//ToExcel(DataGrid1);
}
------解决方案--------------------
是不是你有别的程序打开了这个excel?