首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

導出excel問題,该如何解决

2012-10-20 
導出excel問題C# codeLinkButton onebtn (LinkButton)senderGridViewRow gr onebtn.Parent.Parent as

導出excel問題

C# code
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;


導出一行數據時出現中文亂碼,多行不會出現問題,求大神指點。

[解决办法]
Response.Write("<meta http-equiv=Content-Type content=application/ms-excel;charset=UTF-8>");
加在这个后面Response.Clear();

热点排行