从Asp.net webform应用程序导出griddata到MS excel时出错
我使用Asp.net webform c#。当输出网格数据excel使用时,我收到以下错误消息“文件formate和扩展模式的transport.xls不匹配。该文件可能已损坏或不安全。除非你信任它的来源,不要打开它,你想不pipe怎样打开它“
一旦您点击“是”,数据就会显示正常。
码:
Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls")); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gvmodeoftransport.AllowPaging = false; for (int i = 0; i < gvmodeoftransport.HeaderRow.Cells.Count; i++) { gvmodeoftransport.HeaderRow.Cells[i].Style.Add("background-color", "#df5015"); } gvmodeoftransport.RenderControl(htw); Response.Write(sw.ToString()); Response.End();