JAVA WEB 导出 Excel表格
2015-10-26 17:33
573 查看
<pre name="code" class="java"> public ModelAndView InvoiceExcel(final String mes, final HttpServletRequest request, final HttpServletResponse response) throws Exception { final int huanchong = 2048; Map<String, Object> beans = new HashMap<String, Object>(); ProjectQuery query = new ProjectQuery(); if (!Strings.isNullOrEmpty(mes)) { query = JsonUtil.json2Object(URLDecoder.decode(mes, "UTF-8"), ProjectQuery.class); } List<ProjectView> list = projectService.findAll(); beans.put("list", list); String url = ExcelUtil.exportAndDownload(beans, "ProjectList", request, response);//ProjectList为模板名称
esponse.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("UTF-8"); java.io.BufferedInputStream bis = null; java.io.BufferedOutputStream bos = null; try { File file = new File(url); if (!file.exists()) { file.mkdir(); } if (file.exists()) { response.setContentType("application/x-msdownload;"); response.setHeader("Content-disposition", "attachment; filename=" + new String(file.getName().getBytes("utf-8"), "ISO8859-1")); response.setHeader("Content-Length", String.valueOf(file.length())); bis = new BufferedInputStream(new FileInputStream(url)); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[huanchong]; int bytesRead; while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); } } } catch (Exception e) { e.printStackTrace(); } finally { if (bis != null) { bis.close(); } if (bos != null) { bos.close(); } } return null; }
<img src="https://img-blog.csdn.net/20151026175600657?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<span style="font-family: punctuation, 微软雅黑, Tohoma; font-size: 14.44444465637207px; line-height: 24.44444465637207px;">JQuery EasyUI 新开交流群 511830793</span>
欢迎大家前来与我一起学习,共同进步!
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 使用Python生成Excel格式的图片
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树