IE6导出EXCEL的时候文件名丢失,文件后缀名.xls也丢失
一下代码导出的EXCEL在IE8上都没问题,到了IE6上就出现文件名变了,而且没有后缀名.xls,但是重命名后加上后缀名.xls以后就可以了,里面的数据写入都没错,这是问什么啊,怎么解决 哦????
public bool OutExcel(HttpContext context)
{
try
{
string s = context.Request.Form["SelSearch"];
string s1 = context.Request.Form["HidContent"];
HttpResponse resp;
resp = context.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
string fn = "户表小区:" + DateTime.Now.ToString() + ".xls";
resp.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlPathEncode(fn));
resp.ContentType = "Excel";//设置输出文件类型为excel文件。+ ".xls"
string colHeaders = "";
string ls_item = "";
string condition = "";
if (condition != "")
{
switch (s)
{
case "DistName":
condition += " DistName=" + s1;
break;
case "AreaID":
condition += GetAreaID(s1);
break;
}
}
else
condition = " 1=1 ";
DataTable dt = distbll.GetList(condition).Tables[0];
//表头
colHeaders += "编号\t";
colHeaders += "客户编号\t";
colHeaders += "小区名称\t";
colHeaders += "所属区域\t";
colHeaders += "添加时间\t";
colHeaders += "修改时间\n";
resp.Write(colHeaders);
for (int i = 0; i < dt.Rows.Count; i++)
{
ls_item += dt.Rows[i]["AutoID"].ToString() + "\t";
ls_item += dt.Rows[i]["UnitCode"].ToString() + "\t";
ls_item += dt.Rows[i]["DistName"].ToString() + "\t";
ls_item += dt.Rows[i]["AreaID"].ToString() + "\t";
ls_item += dt.Rows[i]["AddTime"].ToString() + "\t";
ls_item += dt.Rows[i]["ModifiedDate"].ToString() + "\n";
resp.Write(ls_item);
ls_item = "";
}
resp.End();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
------解决方案--------------------
不是ie版本的问题,是编码的问题的,你用utf-8编码试试。建议excel文件不要用中文名就不会出现这种问题了。