日期:2014-05-17  浏览次数:20756 次

導出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();