SpringBoot整合EasyPoi实现导入导出Excel

一、前言

平时我们写代码时常常需要一些导入导出的操作,一般都是用Apache的poi,但是发现很繁琐,总是在Copy… ,无意间发现一款简单粗暴的神器EasyPoi,导入导出很方便,而且支持多种格式的导入导出,下面介绍基于@Excel注解实现简单的导入导出Excel。

码云地址 :easypoi-spring-boot-starter
官方教程:https://easypoi.mydoc.io/


二、 功能

Excel自适应xls和xlsx两种格式,word只支持docx模式

1.Excel导入
  • 注解导入
  • Map导入
  • 大数据量导入sax模式
  • 导入文件保存
  • 文件校验
  • 字段校验

2.Excel导出

  • 注解导出
  • 模板导出
  • html导出

3.Excel转html

4.word导出

5.pdf导出

三、使用EasyPoi
1. SpringBoot项目pom.xml中添加依赖
<dependency>
     <groupId>cn.afterturn</groupId>
     <artifactId>easypoi-spring-boot-starter</artifactId>
     <version>3.2.0</version>
</dependency>
        
2. 工具类(网上很多)
package com.example.demo.utils;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

//Excel导入导出工具类
public class ExcelUtils {
    public static void exportExcel(List<?> list, String title, String sheetName, Class<?> pojoClass, String fileName,
                                   boolean isCreateHeader, HttpServletResponse response) {
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值