首页 > 其他 > 详细

下载导入模板

时间:2018-11-21 14:53:42      阅读:184      评论:0      收藏:0      [点我收藏+]

简单描述:需求要求做下载Excel模板,在模板上填充数据,然后在做导入功能。

//html代码
<div class="btn-group">
<button class="btn sbold green" id="submitRelease" onclick="downloadTemplate();">
   <span class="ladda-label">下载模板</span>
</button>
</div> 

//js代码
function downloadTemplate() {
window.location.href = rootPath + "/vrxx/abc/downloadTemplate"
} 

 

//后台java代码
@ResponseBody
@RequestMapping("/downloadTemplate")
public void downloadTemplate(HttpServletResponse response, HttpSession session) {
try {
InputStream inputStream = (InputStream) this.getClass().getClassLoader().getResourceAsStream("excelexport/rights.xlsx");
response.setContentType("application/zip");
OutputStream out = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename=" + "base" + ".xlsx");
int b = 0;
byte[] buffer = new byte[1000000];
while (b != -1) {
b = inputStream.read(buffer);
if (b != -1) out.write(buffer, 0, b);
}
inputStream.close();
out.close();
out.flush();
} catch (IOException e) {
e.printStackTrace();
logger.error("模板下载失败");
}
}

 说明:首先,括号里的参数session,没有用到,可以去掉。

    其次,excelexport/rights.xlsx这个模板excel文件是存放在项目根目录的resources下

技术分享图片

 

下载导入模板

原文:https://www.cnblogs.com/xuchao0506/p/9994699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!