导出到 Excel 文件名
Export to Excel file name
我编写了将 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);
但非英语名称(如阿拉伯语)的文件名显示不正确。我如何保存非英文名称的文件?
谢谢
用
包装文件名
Server.UrlEncode
例如:
string FileName = Server.UrlEncode(Title + ".xls");
而且有效!!!!
我编写了将 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);
但非英语名称(如阿拉伯语)的文件名显示不正确。我如何保存非英文名称的文件?
谢谢
用
包装文件名Server.UrlEncode
例如:
string FileName = Server.UrlEncode(Title + ".xls");
而且有效!!!!