导出Excel中文名乱码解决办法
/// <summary>
/// 文本流送到客户端,关显示为另存为
/// </summary>
/// <param name=”response”>页面response类</param>
/// <param name=”fileName”>另存为的文件名</param>
public void FileWebSaveAs(HttpResponseBase response, string fileName)
{
response.Clear();
response.ClearHeaders();
response.Buffer = false;
response.AddHeader(“Content-Disposition”, “attachment; filename=” + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + “.xls”);
response.ContentType = “application/ms-excel”;
response.ContentEncoding = System.Text.Encoding.UTF8;
//response.Write(DataTableToExcelStr(_dt));
System.IO.MemoryStream ms;
string strExcel = ListToExcelStr(_listItem);
int Step = 1024000;
int startIndex = 0;
int excelLength = strExcel.Length – Step;
while (startIndex < excelLength)
{
ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(strExcel.Substring(startIndex, Step)));
response.BinaryWrite(ms.ToArray());
startIndex += Step;
}
response.BinaryWrite(System.Text.Encoding.UTF8.GetBytes(strExcel.Substring(startIndex, strExcel.Length – startIndex)));
response.Flush();
response.End();
}