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

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - zhangsir

.net 项目 调用webservice 出错,异常信息:对操作“xxx”的回复消息正文进行反序列化时出错。解决方案。 手机版web相关meta配置 网页中点击运行执行代码 js 在页面上模拟多选,蚂蚁线线框 C# 检测程序运行时间的方法,Stopwatch类 js获取url参数值 flash as2 简易手写板,带擦除功能 flash as2 BitmapData应用之 ---- 画双线 svn(版本管理) 去掉(清理)版本信息的方法 sql 数据库显示 正在恢复 as3中parent访问属性所牵涉的强制类型的问题 [AS3]URLVariables传入URL编码字符串时的一些官方无文档的原则 sql 日期 、时间相关 100万个不重复的8位的随机数 flash 中实现斜切变型 使用UpdatePanel 局部刷新出现中文乱码的解决方法!! - zhangsir - 博客园 loaded AS2 swf call function in AS3 holder - zhangsir Rewrite the master page form action attribute in asp.net 2.0 sql2000 跨服务器复制表数据
C#导出csv文件 支持中文的解决方案
zhangsir · 2013-12-24 · via 博客园 - zhangsir
        #region 导出CSV下载
        string exportFileName = "Export" + DateTime.Now.ToString("yyyyMMddHHmmss");
        System.Web.HttpContext context = System.Web.HttpContext.Current;
        StringBuilder sb = new StringBuilder();
        sb.Append("FirstName,LastName,PhoneNo.,State,TimeZone,ZipCode\n");
        for (int i = 0; i < result.PhoneList.Count; i++)
        {
            sb.Append(result.PhoneList[i].FirstName + "," + result.PhoneList[i].LastName + "," + result.PhoneList[i].Phone + "," + result.PhoneList[i].State + "," + result.PhoneList[i].TimeZone + "," + result.PhoneList[i].ZipCode + "\n");
        }
        StringWriter sw = new StringWriter(sb);
        sw.Close();
        context.Response.Clear();
        /* 
         * Acme 2012-07-04 edit 
         *  
        context.Response.Charset = "gb2312"; 
        context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); 
        context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // "application/octet-stream"; //"application/vnd.ms-excel"; //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet                   
        //context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName)); 
        */
        //below is new writing  
        context.Response.Charset = "UTF-8";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentType = "text/csv";
        //主要是下面这一句
        context.Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });
        context.Response.Write(sw);
        context.Response.AppendHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(exportFileName + ".csv", System.Text.Encoding.UTF8).Replace("+", "%20"));
        //context.Response.OutputStream.Write(fileData, 0, fileData.Length);  
        context.Response.Flush();
        context.Response.End();
        #endregion