我将此代码编写为导出GridView到Excel:
System.Web.HttpContext.Current.Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = System.Text.Encoding.UTF8.EncodingName;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
string FileName = Title + ".xls";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
但是非英文名称(例如阿拉伯语)的文件名无法正确显示。如何保存非英文名称的文件?
感谢
答案 0 :(得分:0)
使用
换行文件名Server.UrlEncode
例如:
string FileName = Server.UrlEncode(Title + ".xls");
它有效!!!!