zoukankan      html  css  js  c++  java
  • sqlserver导出为EXcel--CSV格式

     DataTable dt = Connect.BindTable(" SELECT  名称,地址,当前日期  FROM  table   GROUP BY 名称,地址,当前日期 order by 名称,地址,当前日期 desc  ");
      Export(dt);

     /*exel文件导入函数*/
        private void Export(System.Data.DataTable tab)
        {
            StringWriter sw = new StringWriter();
            sw.WriteLine("名称,地址,当前日期");
            foreach (DataRow dr in tab.Rows)
            {
                sw.WriteLine(dr["名称"] + "," + dr["地址"] + "," + dr["当前日期"] );
            }
            sw.Close();
            Response.AddHeader("Content-Disposition", "attachment; filename=test.csv");
            Response.ContentType = "application/ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.Write(sw);
            Response.End();
        }

  • 相关阅读:
    CVS,GIT,Mercurial和SVN比较
    ubuntu-使用终端配置网络
    编写简单的hashCode方法
    编写高质量equals方法
    文件上传和下载
    Java常用命令
    增删查改-MySQL
    Newton迭代法-C++
    二分法-C++
    适配器模式
  • 原文地址:https://www.cnblogs.com/accumulater/p/6698490.html
Copyright © 2011-2022 走看看