• 使用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/

  • 相关阅读:
    JAVA-初步认识-常用对象API(StringBuffer类-插入删除查找修改)
    JAVA-初步认识-常用对象API(StringBuffer类-特点添加功能)
    JAVA-初步认识-常用对象API(String类-练习1)
    JAVA-初步认识-常用对象API(String类-常见功能-intern方法)
    JAVA-初步认识-常用对象API(String类-常见功能-比较)
    JAVA-初步认识-常用对象API(String类-常见功能-判断)
    JAVA-初步认识-常用对象API(String类-常见功能-转换)
    JAVA-初步认识-常用对象API(String类-常见功能-获取-2)
    arcengine导出复本
    PC软件分享
  • 原文地址:https://www.cnblogs.com/jiangwz/p/8892212.html
Copyright © 2020-2023  润新知