zoukankan      html  css  js  c++  java
  • EasyExcel使用

    pom依赖

                <dependency>
                    <groupId>com.alibaba</groupId>
                    <artifactId>easyexcel</artifactId>
                    <version>${easyexcel.version}</version>
                </dependency>
    

     创建excel的Model数据

    @Data
    public class DabaiModel extends BaseRowModel {
        @ExcelProperty(value = "用户名", index = 0)
        private String name;
        @ExcelProperty(value = "编号", index = 1)
        private String idCode;
        private String desc;
    }
    

     未加@ExcelProperty的属性不会被解析写到excel中。  

    导出Excel

    Controller层:

    List<DabaiDto> list=dabaiDao.queryList();
    List<DabaiModel>modelList=new ArrayList<>(list.size());
    foreach(DabaiDto dto:list){
       DabaiModel mo=new DabaiModel();
       BeanUtils.copyProperties(dto,mo);  
    }
    try{
       String filename = URLEncoder.encode("导出excel名", "UTF-8") + ".xls";
       response.setContentType("application/x-download");
       response.setHeader("Content-Disposition", "attachment;filename="+filename);
       OutputStream outputStream = response.getOutputStream();
       ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLS,true);
       Sheet sheet1 = new Sheet(1,0, DabaiModel.class);
       sheet1.setSheetName("sheet1");
       writer.write(modelList, sheet1);
       writer.finish();
    }catch(IOException e){
     
    }
    

      

    @ExcelProperty
  • 相关阅读:
    Oracle面试题目及解答
    java -jar Incompatible argument to function
    plsql 查询到别的用户下面的表
    redis数据类型[string 、list 、 set 、sorted set 、hash]
    redis-cli 常用命令
    js判断浏览器,包括Edge浏览器
    HTMl5的sessionStorage和localStorage
    JS实现密码加密
    sprintf.js
    js-crc32
  • 原文地址:https://www.cnblogs.com/notably/p/13364929.html
Copyright © 2011-2022 走看看