easyexcel填充复杂表格并导出以及使用easyexcel遇到的坑
生活随笔
收集整理的這篇文章主要介紹了
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用法可以查看https://www.yuque.com/easyexcel/doc/fill
沒覆蓋啊
總結
以上是生活随笔為你收集整理的easyexcel填充复杂表格并导出以及使用easyexcel遇到的坑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工程 技术与工程师
- 下一篇: ABB机器人安全板硬件功能介绍+接线方法