zoukankan      html  css  js  c++  java
  • 使用easypoi导出excel

    EasyPOI是在jeecg的poi模块基础上,继续开发独立出来的,可以说是2.0版本,EasyPoi封装的目的和jeecg一致,争取让大家write less do more ,在这个思路上easypoi可以让大家几乎不写代码的情况下完成Excel的导入导出,Excel的模板导出(制作漂亮的Excel),Word模板的导出,让大家从复杂的POI的接口中解脱出来,同时更迅速的完成工作.

    EasyPoi的特性

    •      注解是基础,让大家见名知意

    •      注解是核心,让大家快速开发

    •      简单的导出导入接口,可以快速完成

    •      简单的数据接口,自定义数据

    •      Excel模板,美化的Excel,程序一天,Excel1分钟

    •      Word模板,通知类文件的强大神器

    •      SpringView集成

    easypoi在项目中的应用:

    需要引入的jar包:

            <!--easypoi导出excel-->
            <!--easypoi-base 导入导出的工具包,可以完成Excel导出,导入,Word的导出,Excel的导出功能-->
            <dependency>
                <groupId>org.jeecg</groupId>
                <artifactId>easypoi-base</artifactId>
                <version>2.3.1</version>
            </dependency>
            <!--easypoi-web  耦合了spring-mvc 基于AbstractView,极大的简化spring-mvc下的导出功能-->
            <dependency>
                <groupId>org.jeecg</groupId>
                <artifactId>easypoi-web</artifactId>
                <version>2.3.1</version>
            </dependency>
            <!--easypoi-annotation 基础注解包,作用与实体对象上,拆分后方便maven多工程的依赖管理-->
            <dependency>
                <groupId>org.jeecg</groupId>
                <artifactId>easypoi-annotation</artifactId>
                <version>2.3.1</version>
            </dependency>

    然后在实体类中添加easypoi的注解:

    @ExcelTarget("summaryexcel")
    @Data
    public class SummaryExcel {
    
    
        @Excel(name = "日期", orderNum = "1", mergeVertical = true, isImportField = "date")
        private String date;//当天日期
    
        @Excel(name = "能源类型", orderNum = "2", mergeVertical = true, isImportField = "type")
        private String type;         // 能源类型
    
        @Excel(name = "能源用量", orderNum = "3", mergeVertical = true, isImportField = "sum")
        private Double sum;          // 用量
    }

    然后就可以在controller层直接使用easypoi:

        
      @GetMapping("getexcel")
      public void download(HttpServletRequest request, HttpServletResponse response,String start,String end) throws Exception { // 告诉浏览器用什么软件可以打开此文件 response.setHeader("content-Type", "application/vnd.ms-excel"); // 下载文件的默认名称 response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("数据表","UTF-8") + ".xls"); //编码 response.setCharacterEncoding("UTF-8"); List<SummaryExcel> list = summaryService.summaryexcel(start,end); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), SummaryExcel.class, list); workbook.write(response.getOutputStream()); }

    这样一个简单的用easypoi实现excel导出就完成了。

    easypoi在开源中国:https://www.oschina.net/news/54995/jeecg-easypoi-2-0-3

    easypoi文档:http://easypoi.mydoc.io/

  • 相关阅读:
    IOS上传图片方向问题
    在线抠图的小工具
    Notion笔记工具免费开通教育许可
    多国正在遭遇新型勒索病毒Petya侵袭
    UC 网盘:我又回来了
    数字统计
    Hello,World!
    Unity开发笔记-Timeline利用Clip实现Rewind回放
    Unity开发笔记-Timeline利用Single实现Rewind回放
    Unity开发笔记-PSD自动导出UGUI工具开发要点记录(1)PSD树形结构解析
  • 原文地址:https://www.cnblogs.com/jiangwz/p/8892212.html
Copyright © 2011-2022 走看看