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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 笑萧亦然

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

完整方法如下: