惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
B
Blog
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
月光博客
月光博客
人人都是产品经理
人人都是产品经理
IT之家
IT之家
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
C
Check Point Blog
罗磊的独立博客

博客园 - 笑萧亦然

KingdeeK3-修改单据邮件发送的自定义字段 微软在GitHub上开放源代码 【转】GitHub入门详细讲解 C#自动切换Windows窗口程序,如何才能调出主窗口? 系统颜色对照表 showModalDialog后如何刷新父页面 delegate Demo (一个关于System.Timers.Timer的Demo) 常用SQL关于表的操作 System.Web.HttpException 与 HTTP Error 404.13 - Not Found问题解决说明 SQL 数据库常用的系统存储过程解析 JAVA md5把我气到疯的代码,天哪,神呀,我的C# 啊。 根据经纬度坐标计算两点间几何距离 - 椰子树下 - CSDN博客 获取库中的所有字段的描述/获取某个表中所有字段方法 多个CSS风格共用同一(背景)图片_那一片天_百度空间 学习总结之三(SQL SERVER游标CURSOR的使用) SQL Server 如何锁一个表的某一行 - MS-SQL Server / 基础类 SQL中的系统变量一览 简单的弹出层窗口应用(DIV+JS) - 笑萧亦然 - 博客园 sql中左侧不够自动补0的写法,优!
asp.net 导出excel 中文乱码解决方法 (转)
笑萧亦然 · 2014-07-24 · via 博客园 - 笑萧亦然

用我转载的上一篇文章 Asp.net中把DataTable或DataGrid导出为Excel 导出的文档,中文有乱码现象,
其实要解决中文乱码很简单,设置一下字符集。如下:

  1.    curContext.Response.ContentType = "application/vnd.ms-excel";  
  2. curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");  
  3. curContext.Response.Charset = "gb2312";  
   // 设置编码和附件格式 
                   curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                curContext.Response.Charset = "gb2312";

 另外,在输出的时候,最好加上以下语句:

<meta http-equiv="content-type" content="application/ms-excel; charset=gb2312"/>

  1. dgExport.RenderControl(htmlWriter);  
  2. curContext.Response.Clear();  
  3. curContext.Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + strWriter.ToString());  
  4. curContext.Response.End();  
                // 返回客户端 
                dgExport.RenderControl(htmlWriter);
                curContext.Response.Clear();
                curContext.Response.Write("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=gb2312\"/>" + strWriter.ToString());
                curContext.Response.End();

完整方法如下: