需导入using System.Text;在以下按钮单击事件中实现:private void Button1_Click(object sender, System.EventArgs e)
{
     Response.ContentType = "application/vnd.ms-excel";
     Response.AddHeader("Content-Disposition", "inline;filename="
+   HttpUtility.UrlEncode("下载文件.xls",Encoding.UTF8   )   );   
 
//如果输出为Word,修改为以下代码
//Response.ContentType = "application/ms-word" 
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc") 
StringBuilder sb=new StringBuilder(); 
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
sb.Append("<html><body>");
DataGrid1.RenderControl(hw);
sb.Append("</body></html>"); 
Response.Write(sb.ToString());
Response.End();
}
请大家帮帮忙!!谢谢大家了

解决方案 »

  1.   


    Response.Charset = "GB2312";
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
      

  2.   

    Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            string FileNames = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + FileNames);
            Response.ContentType = "application/ms-excel";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
    这个是我的导出excel
      

  3.   

    太谢谢你了honey52570(给我力量,陪我闯荡!) ...搞定了..
      

  4.   

    Response.Charset = "GB2312";
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");没错
    再BS下楼主
    搞定了也应该给分啊~!
    最少证明下人家的劳动成果吧~!