阿里开源百万级数据导出Excel表格 三步简单导出 附官方文档
生活随笔
收集整理的這篇文章主要介紹了
阿里开源百万级数据导出Excel表格 三步简单导出 附官方文档
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
阿里巴巴Excel導(dǎo)出優(yōu)化速度 ,64M內(nèi)存20秒讀取75M(46W行25列)的Excel(3.0.2+版本)
官方文檔:EasyExcel · 語雀EasyExcel是一個基于Java的簡單、省內(nèi)存的讀...https://www.yuque.com/easyexcel/doc/easyexcel
導(dǎo)入阿里Excel最新依賴
<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.0.5</version></dependency>創(chuàng)建表格實體類
public class NoDataUser {@ExcelProperty("序號") //設(shè)置列名稱private Integer no;@ExcelIgnore //導(dǎo)入時 忽略該屬性private Long consId;@ExcelProperty("用戶戶號")private String consNo;@ExcelIgnoreprivate String orgNo;@ExcelProperty("用戶名稱")private String consName;@ExcelProperty("供電單位")private String orgName;@ExcelProperty("運行容量(kVA)")private Double runCap;@ExcelProperty("電源類型")private String type;public Integer getNo() {return no;}public void setNo(Integer no) {this.no = no;}public Long getConsId() {return consId;}public void setConsId(Long consId) {this.consId = consId;}public String getConsNo() {return consNo;}public void setConsNo(String consNo) {this.consNo = consNo;}public String getOrgNo() {return orgNo;}public void setOrgNo(String orgNo) {this.orgNo = orgNo;}public String getConsName() {return consName;}public void setConsName(String consName) {this.consName = consName;}public String getOrgName() {return orgName;}public void setOrgName(String orgName) {this.orgName = orgName;}public Double getRunCap() {return runCap;}public void setRunCap(Double runCap) {this.runCap = runCap;}public String getType() {return type;}public void setType(String type) {this.type = type;} }導(dǎo)出表格
//要導(dǎo)出的List數(shù)據(jù) List<NoDataUser> noDataUserList = loadCharactService.findNoDataUser(orgNo, type);String fileName = "用戶信息";try (ServletOutputStream out = response.getOutputStream()) {String disposition = "attachment; fileName=" +new String(fileName.getBytes("UTF-8"), "ISO-8859-1") + ".xls";response.setCharacterEncoding("utf8");response.setContentType("text/xls");response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName + ".xls", "UTF-8"));response.setHeader("Content-Disposition", disposition);EasyExcel.write(out, NoDataUser.class).sheet(1).doWrite(noDataUserList);out.flush();} catch (IOException e) {throw new RuntimeException();}總結(jié)
以上是生活随笔為你收集整理的阿里开源百万级数据导出Excel表格 三步简单导出 附官方文档的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: xp重启计算机的快捷键,xp电脑关机重启
- 下一篇: 10-25 查询选修张老师讲授所有课程的