jxls如何动态导出图片

pengzeping java开发  2015-10-27 11:48:01
excel模板:如何动态的吧图片放进去?已经获取到图片的路径.
...全文
107 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
pengzeping 2015-10-27
//导出房源信息 @RequestMapping(value = "/exportHouseInfo1") public void exportHouseInfo1(HttpServletRequest request, HttpServletResponse response,@RequestParam("id")Long id) throws Exception { //获取房源信息 CommercialEstateDTO data = service.getHouseById(Long.valueOf(id)); //获取图片路径 ResourceBundle rb = ResourceBundle.getBundle("config"); String fileUrl = rb.getString("fileUrl"); //获取图片信息 List<UploadFileDTO> fileDTO=service.findUploadFileById(id.toString()); //导出的文件名称 String shopName= data.getShopName()+".xlsx"; //设置文件名称编码 String fileName=URLEncoder.encode(shopName,"UTF-8"); //获取模板路径 //文件都是在/WEB-INF/classes目录下 String templateFileName = request.getSession().getServletContext().getRealPath("/WEB-INF/classes"+"/房源信息模板.xlsx"); //设置响应 response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename="+fileName); OutputStream out=null; InputStream in=null; XLSTransformer transformer = new XLSTransformer(); Map<String,Object> beans = new HashMap<String,Object>(); //获取数据 beans.put("dto", data); try { in=new BufferedInputStream(new FileInputStream(templateFileName)); Workbook workbook=transformer.transformXLS(in, beans); out=response.getOutputStream(); //将内容写入输出流并把缓存的内容全部发出去 workbook.write(out); out.flush(); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (out != null) { try { out.close(); } catch (IOException e) { } } } }
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-27 11:48
社区公告
暂无公告