效果图:

前端页面

<html>
<head>
<title>Test For Excel</title>
<script src="js/jquery.js" />
<script type="text/javascript">
function btnDownExel_Click()
{var url = "TScheduleRExcelDown.aspx";
window.open(url);
}
</script>
</head>
<body>
<div class="form-group" style="margin-left:15%">
<input type="button" name="btnSearch" id="btnDownExel" class="btn btn-default" onclick="btnDownExel_Click()" value="DownExcel" />
</div>
</body>
</html>
后台页面:TScheduleRExcelDown.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
  string sqlNode= "/*你的SQL语句*/";
  //返回table
  DataTable dtAll = DBFunction.ExecuteTableSql(sqlNode);
  DownExcel(dtAll);
} /// <summary>
/// 下载Excel档
/// </summary>
/// <param name="dt">数据源</param>
public void DownExcel(DataTable dt)
{
  HttpResponse resp = System.Web.HttpContext.Current.Response;
  resp.Charset = "utf-8";
  resp.Clear();
  string filename = "在装修店铺表_" + DateTime.Now.ToString("yyyyMMdd");
  resp.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
  resp.ContentEncoding = System.Text.Encoding.UTF8;   resp.ContentType = "application/ms-excel";
  string style = "<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=utf-8\"/>" + "<style> .table{ font: 9pt Tahoma, Verdana; font-weight:bold; color: #000000; text-align:center; background-color:#8ECBE8; }.tableTd{text-align:center;height:21px;background-color:#EFF6FF;}.tdNode{text-align:left;height:21px;background-color:#DDDDFF;}.table th{ font: 9pt Tahoma, Verdana; color: #000000; font-weight: bold; background-color: #8ECBEA; height:25px; text-align:center; padding-left:10px;}</style>";
  resp.Write(style);
  resp.Write("<table class='table'><tr><th>商场</th><th>铺位编号</th><th>装修联系人</th><th>装修联系电话</th><th>装修日期</th></tr>");
  foreach (DataRow tmpRow in dt.Rows)
  {
    resp.Write("<tr><td class='tableTd'>" + tmpRow["BMarketName"].ToString() + "</td><td class='tableTd'> " + tmpRow["BStoreCode"].ToString() + "_" + tmpRow["BStoreName"].ToString() + " </td><td class='tableTd'>" + tmpRow["BContactor"].ToString() + "</td><td class='tableTd'>" + tmpRow["BContactPhone"].ToString() + "</td><td class='tableTd'>" + tmpRow["BCreatedTime"].ToString() + "</td></tr>");
  }
  resp.Write("<table>");   resp.Flush();
  resp.End();
}

asp.net 下载Excel (数据流,不保存)--客户端的更多相关文章

  1. asp.net 下载EXCEL文件

    一.需要导入NPOI 库文件 打开VS2012 工具>>库程序包管理器>>管理解决方案的NuGet程序包,搜索NPOI,如下图 安装完成: 添加 using NPOI.HSSF ...

  2. asp.net导出excel并弹出保存提示框

    asp.net导出excel并弹出保存提示框 2013-07-12 | 阅:1  转:78   |  分享  腾讯空间 人人网 开心网 新浪微博 腾讯微博 搜狐空间 推荐给朋友 举报          ...

  3. IE8下导入EXCEL数据传到客户端以附件下载

    IE8下导入EXCEL数据传到客户端以附件下载方式出现,而不显示数据,解决方法:以text/html格式返回. HttpResponseMessage message = new HttpRespon ...

  4. ASP.NET导出Excel文件

    第一种最常见,并且最简单的方式,直接把GridView导出,导出格式为文本表格形式. protected void btnSaveExcel_Click(object sender, EventArg ...

  5. asp.net导出excel示例代码

    asp.net导出excel的简单方法. excel的操作,最常用的就是导出和导入. 本例使用NPOI实现. 代码:/// <summary> );             ;       ...

  6. Asp.net操作Excel(终极方法NPOI)(转)

    原文:Asp.net操作Excel(终极方法NPOI) 先去官网:http://npoi.codeplex.com/下载需要引入dll(可以选择.net2.0或者.net4.0的dll),然后在网站中 ...

  7. [转] Asp.Net 导出 Excel 数据的9种方案

    湛刚 de BLOG 原文地址 Asp.Net 导出 Excel 数据的9种方案 简介 Excel 的强大之处在于它不仅仅只能打开Excel格式的文档,它还能打开CSV格式.Tab格式.website ...

  8. ASP.NET 状态的传递和保存

    1,HTTP协议是无状态的.服务器不会记住上次给浏览器的处理结果,如果需要上次处理结果(上次状态)就需要浏览器把处理结果值(上次状态)再次给服务器. 2,URL传值:通过URL参数或者通过Form表单 ...

  9. IE11下ASP.NET Forms身份认证无法保存Cookie的问题

    IE11下ASP.NET Forms身份认证无法保存Cookie的问题 折腾了三四天,今天才找到资料,解决了. 以下会转贴,还没来得及深究,先放着,有空再学习下. ASP.NET中使用Forms身份认 ...

随机推荐

  1. cdoj 24 8球胜负(eight) 水题

    8球胜负(eight) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/24 ...

  2. C#综合揭秘——细说多线程

    一.线程的定义  1. 1 进程.应用程序域与线程的关系 进程(Process)是Windows系统中的一个基本概念,它包含着一个运行程序所需要的资源.进程之间是相对独立的,一个进程无法访问另一个进程 ...

  3. linux 磁盘管理学习笔记

    磁盘管理命令:fdisk df du fdisk #查看硬盘分区表 df #查看分区使用情况 du #查看文件占用空间情况lvdisplay #逻辑分区 [1] 李洋.df.du.fdisk:Linu ...

  4. AlarmDemo-with-Database

    https://github.com/anuj7sharma/AlarmDemo-with-Database

  5. FluorineFx 播放FLV 时堆棧溢出解决 FluorineFx NetStream.play 并发时,无法全部连接成功的解决办法

    http://25swf.blogbus.com/tag/FluorineFx/ http://www.doc88.com/p-7002019966618.html  基于Red5的视频监控系统的研究 ...

  6. [Node.js] Broswerify -- 2

    Browserify allows you to leverage 10s of thousands of javascript modules available in the Node Packa ...

  7. 删除sqlserver2008登录记录

    SQL Server Management Studio登陆窗口 清空这些多余的登陆名 删除SqlStudio.bin文件 WinXP: C:\Documents and Settings\用户文件夹 ...

  8. scala命令

    1. intersect方法找出两个字符串的相同字符: scala> "Hello".intersect("World") res3: String = ...

  9. git无法连接bitbucket/github时,出现"Permission deied(publickey)"

    Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you ha ...

  10. Linux编程之《只运行一个实例》

    概述 有些时候,我们要求一个程序在系统中只能启动一个实例.比如,Windows自带的播放软件Windows Medea Player在Windows里就只能启动一个实例.原因很简单,如果同时启动几个实 ...