RSS
热门关键字:  数据挖掘  数据仓库  商业智能  人工智能  搜索引擎
当前位置 :| 首页>编程技术>asp编程>

关于DataGrid数据导入Excel乱码

来源: 作者:unkonwn 时间:2005-07-05 点击:

当导数据到Excel 中时有时会出现乱码


原来代码

  private static void WriteToExcelFromDataGrid(DataGrid dg, string fileName)
  {
   //StringWriter tw = new StringWriter(new CultureInfo( "zh-CHS", false));
   StringWriter tw = new StringWriter();
   HtmlTextWriter hw = new HtmlTextWriter(tw);
   dg.RenderControl(hw);
   
   System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
   response.Clear();
   response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");
   response.ContentType ="application/vnd.ms-excel";
   response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);

数据挖掘实验室


   response.Charset = "gb2312";
   response.Write(tw.ToString());
   response.End();
  }

正确

   response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-7");


原因 utf-8不支持中文


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
匿名?