zoukankan      html  css  js  c++  java
  • web 导出 csv

    public void ProcessRequest(HttpContext context)
            {
                //DownloadFile("教程.csv", "a.csv");

                context.Response.Charset = "UTF-8";
                context.Response.ContentEncoding = System.Text.Encoding.UTF8;
                context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("测试.csv"));
                context.Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF }); 

                context.Response.Write("编号,姓名 1,邸萌");

                context.Response.Flush();
                context.Response.End();
            }

            #region 提供文件下载的方法【只限于服务器端已经存在的文件】
            /// <summary>
            /// 提供文件下载的方法【只限于服务器端已经存在的文件】
            /// </summary>
            /// <param name="fileName">一定要有后缀名。下载保存时文件的名称,可以与实际文件名称不相同,可以是中文</param>
            /// <param name="filePath">要下载文件的虚拟路径</param>
            public void DownloadFile(string fileName, string filePath)
            {
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
                HttpContext.Current.Response.WriteFile(filePath);
            }
            #endregion

  • 相关阅读:
    Deadlock Detecting--转
    java.util.concurrent包详细分析--转
    spring源码分析之spring-core总结篇
    Google和Baidu常用的搜索技巧--转
    极速发展的饿了么订单系统架构演进--转
    唯品会订单分库分表的实践总结以及关键步骤--转
    数据扩展性探讨和总结--转
    MAT使用--转
    Java 8 Stream API详解--转
    论海明威的存在主义宗教意识——存在主义虚无主义。注:部分观点个人不赞同
  • 原文地址:https://www.cnblogs.com/dianyitongxiao/p/4564637.html
Copyright © 2011-2022 走看看