/**
* 导出项目中的excel模板
*
* @param request
* @param response
* @throws FileNotFoundException
*/
@RequestMapping(params = "templateDownload")
public void templateDownload(HttpServletRequest request,HttpServletResponse response)
throws FileNotFoundException {
InputStream inputStream =null;
ServletOutputStream out = null;
try {
//设置response的编码方式
response.setContentType("text/html;charset=UTF-8");
//设置附加文件名
response.setHeader("Content-Disposition","attachment;filename="+
URLEncoder.encode("楼盘价格模板.xls", "UTF-8"));
//文件路径
String path = request.getSession().getServletContext().getRealPath("\\") +
"plug-in\\hjyzg\\excel\\楼盘价格模板.xls";
inputStream = new BufferedInputStream(new FileInputStream(path));
out = response.getOutputStream();
byte[] data = new byte[4 * 1024];
int bytesRead;
while ((bytesRead = inputStream.read(data)) != -1) {
out.write(data, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
out.close();
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
导出excel模板
最新推荐文章于 2024-04-08 17:43:30 发布