导出excel模版
方法一:
public void ToExcel(){
//第一步:获取模版物理路径
string file_1 = Server.MapPath("/Content/Excel/downExcel.xls");
//第二步: 写入客户端
System.IO.FileInfo filet = new System.IO.FileInfo(file_1);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
if (file_0.IndexOf(".xlsx") > 0){
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("订单详情.xlsx"));
}
else if (file_0.IndexOf(".xls") > 0){
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("订单详情.xls"));
}
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
方法二:
public void excelModel(){
//第一步:获取模版物理路径
string path= Server.MapPath("/Content/Excel/downExcel.xls");
//第二步:写入客户端
FileStream fs = new FileStream(path, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
return new EmptyResult();
}
最新文章
- OSG 3D场景渲染编程概述
- 深入剖析tomcat之一个简单的servlet容器
- iOS之UICollectionView详解
- (原创)JAVA多线程二线程池
- Matlab学习笔记 figure函数
- checkstyle配置文件说明
- Autofac全面解析系列(版本:3.5) – [使用篇(推荐篇):2.解析获取]
- Service(一)----->;简单计算
- spring读取prperties配置文件(1)
- # 欢迎使用Markdown编辑器写博客
- while求1+2+3+4+5+6....100的和
- 【Oracle RAC】Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂)
- Eclipse各个版本区别
- 笔记:Javascript 会提升变量声明
- 测试教程网.unittest教程.5. 实例: 找出所有是弱密码的用户
- mysql 5.6 binlog组提交实现原理(转载)
- SpringMvc 启动原理源码分析
- BIOS、MBR、UEFI和GPT关系
- 『cs231n』线性分类器损失函数
- 发现视口(窗口)自适应的新大陆!!vw、vh
热门文章
- pl/sql 过程 函数(写一个过程,输入部门编号,在控制台打印这个部门的名称,总人数,平均工资(基本工资+奖金))
- LeetCode 73. 矩阵置零(Set Matrix Zeroes)
- c 使用lua 示例
- koa 基础(十)原生node.js 在 koa 中获取表单提交的数据
- 20 Django REST Framework 更改PUT/PATCH/DELETE的传参字段,默认为pk
- AWS EC2 外网不能访问的坑
- Python3命名规范
- linux常用命令(12)head命令
- 使用robotframework做接口测试4——搞定接口签名及密码加密
- office web apps安装部署,配置https,负载均衡(四)安装office web apps相关软件