C# 之 下载EXCEL文件,自动用迅雷下载aspx
在浏览器中导出 Excel 得时候,如果浏览器绑定了迅雷,则会下载aspx文件。
解决:下载EXCEL文件,自动用迅雷下载aspx if (Request.QueryString["id"] != null && !string.IsNullOrEmpty(Request.QueryString["id"].ToString()))
{
if (Request.QueryString["oid"] != null && !string.IsNullOrEmpty(Request.QueryString["oid"].ToString()))
{
id = Request.QueryString["id"].ToString();
oid = Request.QueryString["oid"].ToString();
string sqlWhere = string.Format("PProductNumber='{0}' and OrdersNumber='{1}'", id, oid);
List<SonOrders> li= _SonOrdersManager.GetOrdersLists(sqlWhere); if (li.Count > &&li!=null)
{
MemoryStream ms = new MemoryStream();
IWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet();
ICellStyle style1 = workbook.CreateCellStyle();
IFont font = workbook.CreateFont();
font.FontHeightInPoints = ;
style1.SetFont(font);
sheet.DefaultRowHeight = * ; for (int i = ; i < ; i++)
{
if (i == )
sheet.SetColumnWidth(i, * );
else
sheet.SetColumnWidth(i, * );
sheet.SetDefaultColumnStyle(i, style1);
}
IRow row1 = sheet.CreateRow();
ICell cell = row1.CreateCell();
cell.SetCellValue(oid+"_状态详细");
ICellStyle style2 = workbook.CreateCellStyle();
style2.Alignment = HorizontalAlignment.CENTER;
IFont font2 = workbook.CreateFont();
font2.FontHeight = * ;
style2.SetFont(font2);
cell.CellStyle = style2;
sheet.AddMergedRegion(new CellRangeAddress(, , , ));
IRow headerRow = sheet.CreateRow();
headerRow.CreateCell().SetCellValue("产品编号");
headerRow.CreateCell().SetCellValue("下单时间");
headerRow.CreateCell().SetCellValue("原型验收时间");
headerRow.CreateCell().SetCellValue("首件验收时间");
headerRow.CreateCell().SetCellValue("组装验收时间");
headerRow.CreateCell().SetCellValue("厂家出库时间");
headerRow.CreateCell().SetCellValue("现场入库时间");
headerRow.CreateCell().SetCellValue("领用入库时间");
headerRow.CreateCell().SetCellValue("开箱验收时间");
headerRow.CreateCell().SetCellValue("安装完成时间");
headerRow.CreateCell().SetCellValue("安装验收时间"); int j = ;
foreach (SonOrders so in li)
{
IRow dataRow = sheet.CreateRow(j++);
dataRow.CreateCell().SetCellValue(so.SProductNumber);
dataRow.CreateCell().SetCellValue(GetTimeS("下单时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("原型验收时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("首件验收时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("组装验收时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("厂家出库时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("现场入库时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("领用入库时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("开箱验收时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("安装完成时间", so.SProductNumber).ToString());
dataRow.CreateCell().SetCellValue(GetTimeS("安装验收时间", so.SProductNumber).ToString());
}
workbook.Write(ms); ms.Flush();
ms.Position = ; try
{
string[] files = Directory.GetFiles(System.AppDomain.CurrentDomain.BaseDirectory + "excels/");
foreach (string file in files)
{
File.Delete(file);
}
}
catch (Exception exx)
{
Response.Write(exx.Message.ToString());
}
string pname = "状态详细_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
NpoiHelper.SaveToFile(ms, System.AppDomain.CurrentDomain.BaseDirectory + "excels/" + pname);
Response.Redirect("~/excels/" + pname, false);
Response.Clear(); // Response.Clear();
// Response.ClearHeaders();
// Response.Buffer = false;
// Response.ContentType = "application/octet-stream";
// if (Request.Browser.Browser == "Firefox")
// System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + oid + "_状态详细.xls");
//else
// System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(oid + "_状态详细.xls", System.Text.Encoding.UTF8));
// System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", ms.Length.ToString());
// System.Web.HttpContext.Current.Response.BinaryWrite(ms.GetBuffer());
// System.Web.HttpContext.Current.Response.Flush();
// System.Web.HttpContext.Current.Response.End();
}
}
C# 之 下载EXCEL文件,自动用迅雷下载aspx的更多相关文章
- 自动更新开奖数据的excel文件,供大家下载
自动更新开奖数据的excel文件,供大家下载 2010-03-14 20:22 228492人阅读打印来源:乐彩网 作者:eren 很多人拥有自制excel电子表格,常要更新最基本的开奖信息.如有多期 ...
- 前端调用后端接口下载excel文件的几种方式
今天有一个导出相应数据为excel表的需求.后端的接口返回一个数据流,一开始我用axios(ajax类库)调用接口,返回成功状态200,但是!但是浏览器没有自动下载excel表,当时觉得可能是ajax ...
- 在线读取Mongodb数据库下载EXCEL文件
版本:Mongodb2.4.8 通过页面下载Excel文件 jsp <%@ page language="java" contentType="text/html; ...
- JAVA web端JS下载excel文件
JSP代码如下: JSP端引入jquery.easyui.min.js库: <script type="text/javascript" src="<c:ur ...
- 前端下载excel文件功能的三种方法
1 从后端接收json数据,前端处理生成excel下载 JsonExportExcel的github地址:https://github.com/cuikangjie/JsonExportExcel 这 ...
- jsp下载excel文件
jsp下载excel文件的的实现方法很多,今天也遇到这个问题,乱敲了一阵,终于搞定了,记下来和朋友们分享吧. 假设需要下载excel文件的jsp页面名为:down.jsp 对应的后台action名为: ...
- angularJS通过post方法下载excel文件
最近工作中遇到,要使用angularJS的post方法来下载excel的情况.网上找到一个帖子:http://stackoverflow.com/questions/22447952/angularj ...
- NodeJs实现下载Excel文件
nodejs作为一门新的语言,报表功能也不是十分完善. (1).js-xlsx : 目前 Github 上 star 数量最多的处理 Excel 的库,支持解析多种格式表格XLSX / XLSM / ...
- ASP.NET MVC实现Excel文件的上传下载
在应用系统开发当中,文件的上传和下载是非常普遍的需求.在基于.NET的C/S架构的项目开发当中,有多种方案可以实现文件的上传和下载(httpwebrequest.webclient等),而且多采用异步 ...
随机推荐
- jquery获取浏览器URL参数
getRequestParams:function(param){ var reg = new RegExp("(^|&)" + param + "=([^&am ...
- hibernate框架学习之增删改查helloworld
插入数据删除数据修改数据查询单条数据查询多条数据 HelloWorldApp.java package cn.itcast.h3.helloworld; import org.hibernate.Se ...
- 一道搜索题【2013 noip提高组 DAY2 t3】华容道
这篇不多说,具体的解释都在程序里 题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果 ...
- centos6下安装php7的memcached扩展
安装php7的memcached扩展 .编译安装libmemcached- wget https://launchpadlibrarian.net/165454254/libmemcached-1.0 ...
- 快速安装freeswitch
前不久在Centos 6.4上安装了一台Freeswitch,测试已经OK.为了测试FS 的集群效果,从新在安装一台FS,快速安装的过程如下: 方案一:快速安装前提:不用重新下载Freeswitch. ...
- Windows 下搭建 SVN服务器及使用
目录 一 .安装Visual SVN 二.配置SVN 三.安装TortoiseSVN 四.上传项目到远程仓库 五.从远程仓库下载项目 六.检出项目 七.版本回退 参考链接 http://blog.cs ...
- 百度echarts插件x轴坐标显示不全决解方法
X轴显示不全: xAxis.axisLabel.interval number, Function [ default: 'auto' ] 坐标轴刻度标签的显示间隔,在类目轴中有效. 默认会采用标签不 ...
- 【原创】大数据基础之Hive(5)hive on spark
hive 2.3.4 on spark 2.4.0 Hive on Spark provides Hive with the ability to utilize Apache Spark as it ...
- 饿了么vue-cli3.0+cube-ui笔记
1.目录结构 模板文件是public里的index.html,运行项目的时候,会引用src/main.js(入口文件) 详细文档在这里:https://cli.vuejs.org/zh/config/ ...
- vue项目中实现复制内容到剪贴板
项目中要实现分享功能,现在各种接口都关闭了,而且不同的浏览器要使用不同的代码,最后决定直接复制url,然后手动分享 Vue中使用了vue-clipboard2 github地址:https://git ...