导出的excel表的名称为什么是乱码?

wjb0016 2006-10-27 10:56:09
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();
}
...全文
310 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Onlyzhugf 2006-10-31
  • 打赏
  • 举报
回复
System.Text.Encoding.GetEncoding("GB2312")--〉System.Text.Encoding.Default
飞83 2006-10-31
  • 打赏
  • 举报
回复
GetEncoding("GB2312");改为GetEncoding("utf-7");
试试
seemwind 2006-10-31
  • 打赏
  • 举报
回复
不支持中文
股神 2006-10-28
  • 打赏
  • 举报
回复
??顶
wjb0016 2006-10-28
  • 打赏
  • 举报
回复
顶上来
seemwind 2006-10-28
  • 打赏
  • 举报
回复
还是编码问题

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧