首页 > 学院 > 开发设计 > 正文

制作excle报盘模板

2019-11-08 01:53:16
字体:
来源:转载
供稿:网友

前端jsp(简略):

<!-- 报盘模板下载 -->						<a href="${base!}/get_template.do" style="cursor: point;text-decoration: underline;font-size: 14px;display: inline-block;float: right;margin-right: 10px;color: #007bbf;background-color:#f5fafc;line-height:35px;">模板下载</a>

servlet:

@RequestMapping("get_template.html")	public void downloadTemplate(HttpServletRequest request, HttpServletResponse response){		OutputStream out = null;		try {			String path = request.getsession().getServletContext().getRealPath("/");			String fileName = new String(("报盘模板.xls").getBytes("GBK"), "ISO8859_1");			response.setContentType("application/vnd.ms-Excel");			response.setHeader("Content-disposition", "attachment;filename=/"" + fileName + "/"");			out = response.getOutputStream();			String filePath = path + "/WEB-INF/excelTemplate/pbpweb.xls";			InputStream inputSteam =new FileInputStream(filePath);			HSSFWorkbook wb = new HSSFWorkbook(inputSteam);			inputSteam.close();			wb.write(out);			wb.close();		} catch (Exception ex) {			ex.PRintStackTrace();		} finally {			try {				out.close();			} catch (IOException e) {				e.printStackTrace();			}		}	}

报盘模板存放位置:

项目根目录:

/WEB-INF/excelTemplate/pbpweb.xls


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表