下载excel模板,导入数据时需要用到
页面代码:
<form id="form1" enctype="multipart/form-data">
<div style="float:right">
<button type="button" class="btn btn-primary" onclick="$('#fileUpload').click()" id="reviewFile">浏览</button>
<button class="btn btn-primary" type="button" style="margin-left:5px;height:30px;" id="dataExport">批量导入</button>
<input type="button" class="btn btn-primary" style="margin-left:5px;height:30px;" id="downLoad" value="下载模板">
</div>
<div style="float:right;margin-top:5px">
<input id="fileUpload" name="fileUpload" type="file" style="display:none" />
<input id="fileText" type="text" class="form-control" disabled />
</div>
<script>
$("#fileUpload").change(function () {
$("#fileText").val($(this).val());
})
</script>
</form>
js代码:
//下载excel模板
$("#downLoad").click(function () {
//方式1
window.open('/BaseInfoPage/DowntTemplate'); //方式2 此方式还未解锁
//$.ajax({
// url: "/BaseInfoPage/DownLoadExcel", //处理页面的路径
// data: { fileName: "大件运输许可导入模板.xls" }, //要提交的数据是一个JSON
// type: "POST", //提交方式
// dataType: "JSON", //返回数据的类型 //TEXT字符串 JSON返回JSON XML返回XML
// success: function (data) {
// console.log(data);
// },
// error: function (msg) {
// //layer.msg('!', { icon: 1, time: 1000 }, function () { // //});
// //layer.msg(msg, { icon: 2, time: 2000 });
// }
//}) //方式3
//param = "fileName=" + "大件运输许可模板.xls";
//window.location.href = "/BaseInfoPage/DownLoadExcel?" + param;
})
c#后台代码:
/// <summary>
/// 下载excel模板1
/// </summary>
/// <param name="fileName">文件名</param>
public void DownLoadExcel(string fileName)
{
if (Request.Cookies["LoginValue"] == null) Response.Redirect("../Login/LoginPage"); try
{
string path = AppDomain.CurrentDomain.BaseDirectory + "\\ExcelTemplate\\" + fileName + "";//文件路径
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);//读取文件路径
byte[] buffer = new byte[fs.Length];
fs.Position = ;
fs.Read(buffer, , (int)fs.Length);
Response.Clear();
Response.AddHeader("Content-Length", fs.Length.ToString());
Response.ContentType = "application/xls";
Response.AddHeader("Content-Disposition", "inline;FileName=大件运输许可导入模板.xls");
fs.Close();
Response.BinaryWrite(buffer);
Response.OutputStream.Flush();
Response.OutputStream.Close();
//Response.OutputStream.Write(buffer, 0, (int)fs.Length);
}
catch (Exception ex)
{
CSysCfg.WriteLog("获取文档异常:" + ex.Message);
} }
/// 下载excel模板2
public ActionResult DowntTemplate(HttpPostedFileBase file)
{
//模板文件的路径
string filePath = Server.MapPath("~/ExcelTemplate/大件运输许可导入模板.xls");////获取文件路径
if (System.IO.File.Exists(filePath))
{
string strfileName = Path.GetFileName(filePath);//获取文件名称
return File(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), "application/octet-stream", strfileName);
}
else
{
return Content("模板文件找不到!请检查文件是否存在!");//提示用户
}
}
下载excel模板,导入数据时需要用到的更多相关文章
- 从Excel中导入数据时,提示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决办法
注意,64位系统,用64位的补丁文件; https://www.cnblogs.com/A2008A/articles/2438962.html 操作系统:使用的是64位的Windows Server ...
- vue Excel导入,下载Excel模板,导出Excel
vue Excel导入,下载Excel模板,导出Excel vue Excel导入,下载Excel模板 <template> <div style="display: ...
- java的poi技术下载Excel模板上传Excel读取Excel中内容(SSM框架)
使用到的jar包 JSP: client.jsp <%@ page language="java" contentType="text/html; charset= ...
- SQL Server导入数据时“启用标示插入”详解
在SQL Server中导入数据时,会有一个"启用标示插入"的选项,突然间懵逼了,这到底啥意思?我选与不选这个选项,结果好像没区别!不科学啊这,"存在即合理", ...
- 转 SSIS处理导入数据时, 存在的更新, 不存在的插入
SSIS处理导入数据时, 存在的更新, 不存在的插入 分类: DTS/SSIS2006-09-10 12:43 18185人阅读 评论(22) 收藏 举报 ssissql servermicrosof ...
- [MySQL]load data local infile向MySQL数据库中导入数据时,无法导入和字段不分离问题。
利用load data将文件中的数据导入数据库表中的时候,遇到了两个问题. 首先是load data命令无法执行的问题: 命令行下输入load data local infile "path ...
- SQLSERVER:大容量导入数据时保留标识值 (SQL Server)
从MSDN上看到实现大容量导入数据时保留标识值得方法包含三种: MSDN链接地址为:https://msdn.microsoft.com/zh-cn/library/ms178129.aspx 感觉M ...
- MSSQL导入数据时,出现“无法截断表 因为表正由Foreign key引用”错误
* 错误 0xc002f210: 准备 SQL 任务: 执行查询“TRUNCATE TABLE [dsc100552_db].[dbo].[ALV_SalesBigClass] ”失败,错误如下:“无 ...
- 使用Sqoop从mysql向hdfs或者hive导入数据时出现的一些错误
1.原表没有设置主键,出现错误提示: ERROR tool.ImportTool: Error during import: No primary key could be found for tab ...
随机推荐
- 带你学够浪:Go语言基础系列 - 10分钟学方法和接口
文章每周持续更新,原创不易,「三连」让更多人看到是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 对于一般的语言使用者来说 ,20% 的语言特性就能够满 ...
- Blazor带我重玩前端(二)
概览 Blazor目前有两种托管模式,一种是Server-Side模式,一种是WebAssembly模式.官方首先支持的是Service-Side模式,使用WebAssembly模式,需要更新到最新版 ...
- List集合-02.LinkedList
2.LinkedList 2.1 UML继承关系图 2.2 底层存储节点 通过内部类Node存储,可以看出是双向的链表结构 private static class Node<E> { E ...
- Log4j的使用说明
Log4j基本使用方法 Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式.日志信息的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定 ...
- HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...
- sql语句replace函数的使用
SQL中的替换函数replace()使用 语法 REPLACE ( string_expression , string_pattern , string_replacement ) 参数 strin ...
- [JAVA]解决不同浏览器下载附件的中文名乱码问题
附件下载时,遇到中文附件名的兼容性问题,firefox.chrome.ie三个派系不兼容,通过分析整理,总结出处理该问题的办法,记录如下: 1.文件名编码 服务器默认使用的是ISO8859-1,而我们 ...
- Qt-文件系统
1 简介 参考视频:https://www.bilibili.com/video/BV1XW411x7NU?p=45 参考文档:<Qt教程.docx> 说明:本文主要介绍Qt的文件系统. ...
- Python函数06/装饰器
Python函数06/装饰器 目录 Python函数06/装饰器 内容大纲 1.装饰器 1.1 开放封闭原则 1.2 装饰器 2.今日练习 内容大纲 1.装饰器 1.装饰器 1.1 开放封闭原则 扩展 ...
- 数据可视化之PowerQuery篇(十九)PowerBI数据分析实践第三弹 | 趋势分析法
https://zhuanlan.zhihu.com/p/133484654 本文为星球嘉宾"海艳"的PowerBI数据分析工作实践系列分享之三,她深入浅出的介绍了PowerBI ...