急啊 在线等啊 ~~~~ 导出问题
比如本来我的中文名是“列表.xls”,但是导出的excel中的标题和工作表名都成了:%e5%88%97%e8%a1%a8 1 .xls ,如果用英文名就没有问题,试了
HttpUtility.UrlEncode的方法也不行,在线等各位高手解答
代码如下:
public static void DtToExcel(DataTable dt, string FileName)
{
System.Web.HttpResponse httpResponse = System.Web.HttpContext.Current.Response;
httpResponse.Clear();
System.Web.UI.WebControls.GridView dataGrid = new System.Web.UI.WebControls.GridView();
dataGrid.DataSource = dt;
dataGrid.AllowPaging = false;
dataGrid.HeaderStyle.BackColor = System.Drawing.Color.White;
dataGrid.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dataGrid.HeaderStyle.Font.Bold = true;
dataGrid.RowDataBound += new GridViewRowEventHandler(dataGrid_RowDataBound);
dataGrid.DataBind();
string aa = HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8);
httpResponse.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)); //filename="*.xls";
//httpResponse.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
//httpResponse.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
httpResponse.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
dataGrid.RenderControl(hw);
httpResponse.Write(tw.ToString());
httpResponse.End();
}