导出的excel表的名称为什么是乱码?
public static void ExportDataSetToExcel(Page page,DataSet ds,string subjectname)
{
DataTable dt=ds.Tables[0].Copy();
System.IO.StringWriter sw=new System.IO.StringWriter();
string strLine=string.Empty;
foreach(DataColumn col in dt.Columns)
{
strLine += "\t" + col.ColumnName;
}
strLine = strLine.Substring(1);
sw.WriteLine(strLine);
foreach(DataRow dr in dt.Rows)
{
strLine = string.Empty;
foreach(object x in dr.ItemArray)
{
strLine += "\t" + x.ToString();
}
strLine = strLine.Substring(1);
sw.WriteLine(strLine);
}
sw.Close();
// Encoding UTF8 = Encoding.UTF8;
// Encoding gb2312 = Encoding.GetEncoding("gb2312");
// byte[] buffer = gb2312.GetBytes(subjectname);
// subjectname = UTF8.GetString(buffer);
// 我用这段编码还是乱码
page.Response.AddHeader("Content-Disposition", "attachment; filename=" + subjectname + ".xls");
page.Response.ContentType = "application/ms-excel";
page.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
page.Response.Write(sw);
page.Response.End();
}