導出excel問題

chinagzu 2012-10-09 05:55:39
LinkButton onebtn = (LinkButton)sender;
GridViewRow gr = onebtn.Parent.Parent as GridViewRow;
int rowindex = gr.RowIndex;
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=List.xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
for (int i = 0; i < this.dgrd_AppInfo.Rows.Count; i++)
{
this.dgrd_AppInfo.Rows[i].Visible = false;
}
this.dgrd_AppInfo.Rows[rowindex].Visible = true;


導出一行數據時出現中文亂碼,多行不會出現問題,求大神指點。
...全文
67 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinagzu 2012-10-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
Response.Write("<meta http-equiv=Content-Type content=application/ms-excel;charset=UTF-8>");
加在这个后面Response.Clear();
[/Quote]

果然加了這句話就不出現亂碼了,謝謝了,能說明一下原因嗎。
licai1210 2012-10-09
  • 打赏
  • 举报
回复
Response.Write("<meta http-equiv=Content-Type content=application/ms-excel;charset=UTF-8>");
加在这个后面Response.Clear();

110,566

社区成员

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

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

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