js
window.open(路径,‘_self’,‘’,false);
service
public HttpServletResponse templateDownload(HttpServletResponse response) throwsException {
ClassLoader classLoader = this.getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(“META-INF/resources/static/exceltemplate/模板.xlsx”);
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
try {
response.reset();
response.addHeader(“Content-Disposition”, “attachment;filename=” + URLEncoder.encode(“模板” + new Date().getTime()+“.xlsx”,“UTF-8”));
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType(“application/octet-stream”);
if (inputStream != null && toClient != null) {
int temp = 0;
// 开始拷贝
while ((temp = inputStream.read()) != -1) {
// 边读边写
toClient.write(temp);
}
// 关闭输入输出流
inputStream.close();
}
toClient.flush();
toClient.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return response;
}