效果图:

前端页面

<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. 【JavaScript】常用的JS

    JQuery.UnderScoreJS.Zepto 原生JS等

  2. [ES6] 12. Shorthand Properties in ES6

    Where destructuring in ES6 allows you to easily get properties out of an object, this shorthand prop ...

  3. careercup-高等难度 18.1

    18.1  编写一个函数,将两个数字相加,不得使用+或其他算术运算符. int add(int a,int b) { ) return a; int sum=a^b; ; return add(sum ...

  4. C++检测一个文件是否存在

    ifstream::is_open - C++ Reference http://www.cplusplus.com/reference/fstream/ifstream/is_open/ // if ...

  5. CentOS7 安装Docker报错

    安装报错: Transaction check error:  file /usr/lib/systemd/system/blk-availability.service from install o ...

  6. Java_Web使用简单的批处理操作

    之前进行Web开发的时候使用的是myeclipse,但只用过的人都知道,由于其插件太多,而且有很多插件的功能根本就接触不到.所以导致一旦工程稍微大一点就会很卡,虽然之前也对其进行优化过,但还是觉得不太 ...

  7. 从零开始学JAVA(01)-JAVA开发环境安装

    写在前面: 本人没有JAVA基础(包括语法.开发环境),未使用开发工具开发过程序,如果有不对或误导的地方,欢迎指正. 本系列所有文章使用Eclipse,JDK是Version 7 Update 51, ...

  8. IOS 应用中从竖屏模式强制转换为横屏模式

    在 iPhone 应用里,有时我们想强行把显示模式从纵屏改为横屏(反之亦然),CocoaChina 会员 “alienblue” 为我们提供了两种思路 第一种:通过人为的办法改变view.transf ...

  9. iOS 定位系统 知识

    最近在做考勤定位系统 总结一些定位系统的知识. 后期会出一份算法主要攻克地球坐标和火星坐标转换的 1.关于百度的火星坐标定位策略 地图SDK/定位SDK的定位策略: WIFI + 基站 +GPS 三者 ...

  10. ASP.NET通过byte正确安全的判断上传文件格式

    本文介绍一种更安全的方式上传图片,他能有效的防止一些通过修改文件后缀或MIME来伪造的图片的上传,从而保证服务器的安全,希望对大家有所帮助. ASP.NET中在判断文件格式时,我们以前常用的方法就是通 ...