日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/1/18 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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遇到的坑的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。