2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > easyexcel填充复杂表格并导出以及使用easyexcel遇到的坑

easyexcel填充复杂表格并导出以及使用easyexcel遇到的坑

时间:2018-10-30 13:14:16

相关推荐

easyexcel填充复杂表格并导出以及使用easyexcel遇到的坑

读取模板时出现Your file appears not to be a valid OLE2 document

解决办法:另存为97-03年的xls格式即可

准备一个填充模板

其中{xxx}为普通变量,{.xxx} 的为list变量

准备一个实体类

public class vo {private String terminal;private String color;private String number;private String zq;private String dx;private String zt;private String zd;private String rk;public String getTerminal() {return terminal;}public void setTerminal(String terminal) {this.terminal = terminal;}public String getColor() {return color;}public void setColor(String color) {this.color = color;}public String getNumber() {return number;}public void setNumber(String number) {this.number = number;}public String getZq() {return zq;}public void setZq(String zq) {this.zq = zq;}public String getDx() {return dx;}public void setDx(String dx) {this.dx = dx;}public String getZt() {return zt;}public void setZt(String zt) {this.zt = zt;}public String getZd() {return zd;}public void setZd(String zd) {this.zd = zd;}public String getRk() {return rk;}public void setRk(String rk) {this.rk = rk;}}

一个处理导出的controller类

@RequestMapping("/expor")public String exporExcel(HttpServletResponse response) throws IOException {OutputStream outputStream = response.getOutputStream();response.setHeader("Content-disposition", "attachment; filename=" + "catagory.xls");response.setContentType("application/msexcel;charset=UTF-8");//设置类型response.setHeader("Pragma", "No-cache");//设置头response.setHeader("Cache-Control", "no-cache");//设置头response.setDateHeader("Expires", 0);//设置日期头ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(ResourceUtils.getFile("classpath:excelTemplates/template.xls")).build();WriteSheet writeSheet = EasyExcel.writerSheet().build();List<vo> list =new ArrayList<vo>();vo v = new vo();v.setColor("1");v.setDx("1");v.setNumber("1");v.setRk("1");v.setTerminal("1");v.setZq("1");v.setZt("1");v.setRk("1");//填充两行listlist.add(v);list.add(v);FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();excelWriter.fill(list, fillConfig, writeSheet);//填充普通变量Map<String, Object> map = new HashMap<String, Object>();map.put("bussinessRequest", "1");map.put("linkman", "1");map.put("linkphone", "1");map.put("orderdate", "1");map.put("leaddate", "1");map.put("entrct", "1");map.put("comstomer", "1");excelWriter.fill(map, writeSheet);excelWriter.finish();outputStream.flush();response.getOutputStream().close();return "system/test/tableTest";}

填充后并导出的效果,因为controller中忘记设置zd的值所以图中对应zd的表格并没有值

更多easyexcel用法可以查看/easyexcel/doc/fill

没覆盖啊

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。