// <summary>
/// 导出到Excel lichenghu
/// </summary>
/// <param name="dt"></param>
public static void ToExcel(DataTable dt)
{
string sb = "";

foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
sb = sb + dr[i].ToString() + "\t";
}
sb = sb + "\n";
}

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=MyExcel.xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
hw.WriteLine(sb.ToString());
HttpContext.Current.Response.Write(tw.ToString());

HttpContext.Current.Response.End();

hw.Flush();
hw.Close();
tw.Flush();
tw.Close();
}

最新文章

  1. 浅谈ajax
  2. sql server创建备份计划
  3. Oracle存储过程中异步调用的实际操作步骤
  4. nodejs 任务调度使用
  5. ORA-00265: instance recovery required, cannot set ARCHIVELOG
  6. PHP连接SQL Server(sqlsrv)
  7. Failed to create a &#39;System.Type&#39; from the text &#39; &#39; in wpf(无法从文本创建类型)
  8. TCP keepalive under Linux
  9. C++程序原码
  10. text-overflow:ellipsis 的应用(转载)
  11. [置顶] Android安全机制分析
  12. IOS百度地图之---&gt;第二篇《大头针__简单使用及自定义》
  13. AI CV 会议2018
  14. GIF动态图制作
  15. Kafka单节点及集群配置安装
  16. xcode打包命令
  17. Pytest 简明教程
  18. 配置允许匿名用户登录访问vsftpd服务,进行文档的上传下载、文档的新建删除等操作
  19. 20155315 2016-2017-2 《Java程序设计》第七周学习总结
  20. linq 根据指定条件返回集合中不重复的元素

热门文章

  1. oracle之二ASM 管理
  2. 第3课 - 启航Lua之路
  3. 关于java基础_方法的简单习题
  4. Nginx反代MogileFS集群
  5. Docker公共&amp;本地镜像仓库(七)
  6. magento首页
  7. 能否使用GHDL+GTKWave代替Quartus ii
  8. 利用 esp8266 搭建简单物联网项目
  9. scala 传值调用,传名调用
  10. 烦人的Null,你可以走开点了