excel-template-export.rar

上传者: lw112190 | 上传时间: 2021-05-27 10:50:38 | 文件大小: 7KB | 文件类型: RAR
//region 数据源 List resultList = new ArrayList(); Model model = new Model(); model.setCode("01"); model.setName("测试1"); resultList.add(model); model = new Model(); model.setCode("02"); model.setName("测试2"); resultList.add(model); //endregion //获得模版 File directory = new File("src/main/resources/templates"); String templatePath = directory.getCanonicalPath(); String templateFile = templatePath + "\\template.xls"; //导出文件名 SimpleDateFormat simpl = new SimpleDateFormat("yyyyMMddHHmmss"); String currntTime = simpl.format(new Date()); String fileName = currntTime + "报表.xls"; //将结果放入 Map beans = new HashMap(); List values = new ArrayList(); values.add(resultList); beans.put("values", values); beans.put("title", "测试title"); //文件名称统一编码格式 fileName = URLEncoder.encode(fileName, "utf-8"); //生成的导出文件 File destFile = File.createTempFile(fileName, ".xls"); //transformer转到Excel XLSTransformer transformer = new XLSTransformer(); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { //将数据添加到模版中生成新的文件 transformer.transformXLS(templateFile, beans, destFile.getAbsolutePath()); //将文件输入 InputStream inputStream = new FileInputStream(destFile); //设置response参数,可以打开下载页面 response.reset(); //设置响应文本格式 response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1")); //将文件输出到页面 ServletOutputStream out = response.getOutputStream(); bis = new BufferedInputStream(inputStream); bos = new BufferedOutputStream(out)

文件下载

资源详情

[{"title":"( 7 个子文件 7KB ) excel-template-export.rar","children":[{"title":"pom.xml <span style='color:#111;'> 1.80KB </span>","children":null,"spread":false},{"title":"src","children":[{"title":"test","children":[{"title":"java","children":[{"title":"com","children":[{"title":"example","children":[{"title":"demo","children":[{"title":"DemoApplicationTests.java <span style='color:#111;'> 215B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true},{"title":"main","children":[{"title":"resources","children":[{"title":"static","children":null,"spread":false},{"title":"templates","children":[{"title":"template.xls <span style='color:#111;'> 22.50KB </span>","children":null,"spread":false}],"spread":true},{"title":"application.properties <span style='color:#111;'> 1B </span>","children":null,"spread":false}],"spread":true},{"title":"java","children":[{"title":"com","children":[{"title":"example","children":[{"title":"demo","children":[{"title":"TestController.java <span style='color:#111;'> 3.47KB </span>","children":null,"spread":false},{"title":"Model.java <span style='color:#111;'> 384B </span>","children":null,"spread":false},{"title":"DemoApplication.java <span style='color:#111;'> 317B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}],"spread":true}]

评论信息

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明