23.从零开始学springboot-excel导入导出

springboot + POI 导入导出excel的API接口实现 详细学习可参考博客:Java导出Excel(Poi详解)_Action_Wang的博客-优快云博客_poi导出excel 一、添加依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>5.2.0</version> </dependency& 阅读详情

前言

上一章作者分享了mybatis通用mapper的实用。在实际开发中,我们常常会用到excel导入导出相关的功能,本章,作者将分享一个实用的excel操作案例,实现excel的导入导出功能。

亮点:

  • excel导入反射java实体
  • excel导出使用模版

这边简单解释下。
excel导入反射java实体:
首先我们讲下正常实现excel导入的方法,如下伪代码

public List<Student> importExcel(File excelFile, Student student){
    List<Student> list = new ArrayList<Student>();
    for (excelFile) {
        Student s = new Student();
        //excel的第一行的第一列为name
        student.name = excelFile.row[0].column[0];
        //excel的第一行的第二列为age
        student.age = excelFile.row[0].column[1];
        list.add(s);
    }
    return list;
}

可以看到,我们实现了将excel数据列转换为student实体的逻辑。那么,问题来了,以后我想转为teacher实体怎么办?在写一个类似的方法?可以看出,这种方式在方法体内部实现实体类属性与excel列的绑定,很不灵活。那么,能不能传入一个实体类,在运行时,动态的获取该实体的属性实现绑定呢?。此时就很有必要了解java的反射机制了。
JAVA反射机制是在运行状态中,对于任意一个实体类,都能够知道这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意方法和属性。
我们再看看利用反射机制实现excel导入

public  <T extends Object> List<T> importExcel(File excelFile, Class<T> clazz) {
    List<T> list = new ArrayList<>();
    //获取类的所有属性
    Field[] fields = clazz.getDeclaredFields();
    T obj = null;
    for (excelFile){
        // 创建实体
        obj = clazz.newInstance();
        for (Field f : fields) {
            //属性赋值,实现属性和excel列的绑定关系
        }
        list.add(obj);
    }
    return list;
}

可以看到,利用反射机制实现的导入方法更加灵活,这样就可以使其更加通用。

excel导出使用模版
实现过excel导出功能的可能都知道,excel最麻烦的就是编写样式,尤其是样式复杂的表格。仔细观察表格,你会发现,正常复杂的都是表头样式,往往是这样的(举个简单的例子)
4.png
然后下半部分可能就是正常的列表展示。
那么我们能不能把这复杂的部分抽出来,单独由人工来做(毕竟office建立这么一个表格so easy,用代码去画简直抓狂。),而后,我们代码读取这个表格,动态填充数据呢?答案,是肯定的。在接下来的案例中你会看到这样的实现。

目录结构

1.png

添加依赖

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>

        <!-- SpringBoot通用Mapper依赖 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.1.5</version>
        </dependency>

        <!-- excel依赖 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>

        <!-- 实用工具 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>  

2.png

这里我们除了使用了poi excel的依赖,还使用了上章用过的通用mapper依赖,以及lombok依赖,关于lombok依赖,你可以简单理解为一个工具包,这样我们编写实体类时只需要使用

@Setter
@Getter

两个注解即可自动实现类属性的set和get方法,省了不少事。

添加配置

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver

完善代码

我们先实现excel的工具类

utils/excel/ExcelAnnotation

package com.mrcoder.sbmexcel.utils.excel;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelAnnotation {

    /**
     * 列索引
     *
     * @return
     */
    public int columnIndex() default 0;

    /**
     * 列名
     *
     * @return
     */
    public String columnName() default "";

}

ExcelAnnotation这个类实现了一个自定义的注解,定义了两个属性,这样我们可以在实体类中使用

//columnIndex定义excel的列,columnName定义表列名称
@ExcelAnnotation(columnIndex = 1, columnName = "姓名")
private String name;

意思就是导入的excel第二列对应数据表的name列。
此处注意,excel索引是从0开始的。

我们看下需要导入的excel表格结构
3.png
第一列需要是我们无需导入的,所以,我们定义实体类时,excel注解从1开始。

接下来我们定义实体类
model/Excel

package com.mrcoder.sbmexcel.model;

import com.mrcoder.sbmexcel.utils.excel.ExcelAnnotation;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Setter
@Getter
@Table(name = "excel")
@Accessors(chain = true)
public class Excel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
  
    @ExcelAnnotation(columnIndex = 1, columnName = "姓名")
    private String name;

    @ExcelAnnotation(columnIndex = 2, columnName = "年龄")
    private Integer age;

    @ExcelAnnotation(columnIndex = 3, columnName = "身高")
    private Double height;

    @ExcelAnnotation(columnIndex = 4, columnName = "体重")
    private Double weight;

    @ExcelAnnotation(columnIndex = 5, columnName = "学历")
    private String edu;
    private Date createTime;
    private Date updateTime;
    private Integer status;
}

从实体类中可以看出,我们使用了

@Setter
@Getter

lombok注解,所以在该实体中无需手写get和set方法。

然后我们实现excel读取反射成实体的工具类
utils/excel/ExcelUtil

package com.mrcoder.sbmexcel.utils.excel;
import java.io.*;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
/**
 * Excel 工具类
 *
 * @author mrcoder
 * @version 1.0 2019.05.29
 */
public class ExcelUtil {

    /**
     * 读取excel反射实体
     *
     * @param file  MultipartFile
     * @param clazz entity
     * @return
     * @throws RuntimeException
     */
    public static <T extends Object> List<T> readExcelObject(MultipartFile file, Class<T> clazz) {

        // 存储excel数据
        List<T> list = new ArrayList<>();
        Workbook wookbook = null;
        InputStream inputStream = null;

        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException("文件读取异常");
        }

        // 根据excel文件版本获取工作簿
        if (file.getOriginalFilename().endsWith(".xls")) {
            wookbook = xls(inputStream);
        } else if (file.getOriginalFilename().endsWith(".xlsx")) {
            wookbook = xlsx(inputStream);
        } else {
            throw new RuntimeException("非excel文件");
        }

        // 得到一个工作表
        Sheet sheet = wookbook.getSheetAt(0);

        // 获取行总数
        int rows = sheet.getLastRowNum() + 1;
        Row row;

        // 获取类所有属性
        Field[] fields = clazz.getDeclaredFields();

        T obj = null;
        int coumnIndex = 0;
        Cell cell = null;
        ExcelAnnotation excelAnnotation = null;
        for (int i = 1; i < rows; i++) {
            // 获取excel行
            row = sheet.getRow(i);
            //此处用来过滤空行
            Cell cell0 = row.getCell(0);
            cell0.setCellType(CellType.STRING);
            Cell cell1 = row.getCell(1);
            cell1.setCellType(CellType.STRING);
            if (cell0.getStringCellValue() == "" && cell1.getStringCellValue() == "") {
                continue;
            }
            try {
                // 创建实体
                obj = clazz.newInstance();
                for (Field f : fields) {
                    // 设置属性可访问
                    f.setAccessible(true);
                    // 判断是否是注解
                    if (f.isAnnotationPresent(ExcelAnnotation.class)) {
                        // 获取注解
                        excelAnnotation = f.getAnnotation(ExcelAnnotation.class);
                        // 获取列索引
                        coumnIndex = excelAnnotation.columnIndex();
                        // 获取单元格
                        cell = row.getCell(coumnIndex);
                        // 设置属性
                        setFieldValue(obj, f, wookbook, cell);
                    }
                }
                System.out.println(obj);
                // 添加到集合中
                list.add(obj);
            } catch (InstantiationException e1) {
                e1.printStackTrace();
            } catch (IllegalAccessException e1) {
                e1.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("excel文件内容出错");
            }
        }
        try {
            //释放资源
            wookbook.close();
            inputStream.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 绑定实体值
     *
     * @param obj      Object
     * @param f        Field
     * @param wookbook Workbook
     * @param cell     Cell
     * @return
     * @throws RuntimeException
     */
    private static void setFieldValue(Object obj, Field f, Workbook wookbook, Cell cell) {
        try {

            cell.setCellType(CellType.STRING);

            if (f.getType() == byte.class || f.getType() == Byte.class) {

                f.set(obj, Byte.parseByte(cell.getStringCellValue()));

            } else if (f.getType() == int.class || f.getType() == Integer.class) {

                f.set(obj, Integer.parseInt(cell.getStringCellValue()));

            } else if (f.getType() == Double.class || f.getType() == double.class) {

                f.set(obj, Double.parseDouble(cell.getStringCellValue()));

            } else if (f.getType() == BigDecimal.class) {

                f.set(obj, new BigDecimal(cell.getStringCellValue()));

            } else {

                f.set(obj, cell.getStringCellValue());

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 对excel 2003处理
     */
    private static Workbook xls(InputStream is) {
        try {
            // 得到工作簿
            return new HSSFWorkbook(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 对excel 2007处理
     */
    private static Workbook xlsx(InputStream is) {
        try {
            // 得到工作簿
            return new XSSFWorkbook(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

该工具类接受上传excel文件,以及实体类参数,主要就是将每一行的excel数据转换成一个实体,这样方便我们后续批量入库操作。

mapper/ExcelMapper

package com.mrcoder.sbmexcel.mapper;
import com.mrcoder.sbmexcel.model.Excel;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.ExampleMapper;
import tk.mybatis.mapper.common.Mapper;

public interface ExcelMapper extends Mapper<Excel>, InsertListMapper<Excel>, ExampleMapper<Excel> {
}

service/ExcelService

package com.mrcoder.sbmexcel.service;


import com.mrcoder.sbmexcel.mapper.ExcelMapper;
import com.mrcoder.sbmexcel.model.Excel;
import com.mrcoder.sbmexcel.utils.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ExcelService {


    @Autowired
    private ExcelMapper excelMapper;


    //excel导入
    public int importExcel(HttpServletRequest request) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        MultipartFile excel = multipartRequest.getFile("filename");

        try {
            List<Excel> excelData = ExcelUtil.readExcelObject(excel, Excel.class);
            //检查每列数据
            for (int i = 0; i < excelData.size(); i++) {
                excelData.get(i).setStatus(1);
                Date time = new Date();
                excelData.get(i).setCreateTime(time);
                excelData.get(i).setUpdateTime(time);
            }
            //批量导入
            return excelMapper.insertList(excelData);

        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }


    //excel导入
    public void exportExcel(HttpServletResponse response) {
        try {
            // 1.读取Excel模板
            File file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + "excel/export.xlsx");
            InputStream in = new FileInputStream(file);
            XSSFWorkbook wb = new XSSFWorkbook(in);
            // 2.读取模板里面的所有Sheet
            XSSFSheet sheet = wb.getSheetAt(0);
            // 3.设置公式自动读取
            sheet.setForceFormulaRecalculation(true);
            // 4.向相应的单元格里面设置值
            XSSFRow row;

            // 5.得到第二行
            row = sheet.getRow(1);
            // 6.设置单元格属性值和样式
            row.getCell(1).setCellValue("张三");
            row.getCell(3).setCellValue("18");
            row.getCell(6).setCellValue("本科");
            row.getCell(8).setCellValue(new Date());

            row = sheet.getRow(2);
            row.getCell(1).setCellValue("1511xxxx234");
            row.getCell(3).setCellValue("广东");
            row.getCell(6).setCellValue("本科");

            row = sheet.getRow(3);
            row.getCell(1).setCellValue("180");
            row.getCell(3).setCellValue("已婚");
            row.getCell(6).setCellValue("深圳");
            row.getCell(8).setCellValue("2");

            row = sheet.getRow(4);
            row.getCell(1).setCellValue("60");
            row.getCell(3).setCellValue("中国");
            row.getCell(6).setCellValue("其它");
            row.getCell(8).setCellValue("备注");

            //单元格合并
            row = sheet.getRow(6);
            row.getCell(0).setCellValue("合并列");
            CellRangeAddress region = new CellRangeAddress(6, 6, 0, 5);
            sheet.addMergedRegion(region);

            //单元格设置背景色
            CellStyle style = wb.createCellStyle();
            style.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            row.getCell(0).setCellStyle(style);

            //设置单元格边框
            row = sheet.getRow(8);
            XSSFCellStyle style2 = wb.createCellStyle();
            style2.setBorderBottom(BorderStyle.DOUBLE);
            style2.setBorderRight(BorderStyle.DOUBLE);
            style2.setBorderLeft(BorderStyle.DOUBLE);
            style2.setBorderTop(BorderStyle.DOUBLE);
            style2.setBottomBorderColor(IndexedColors.SKY_BLUE.getIndex());
            style2.setRightBorderColor(IndexedColors.SKY_BLUE.getIndex());
            row.getCell(0).setCellStyle(style2);

            // 7.设置sheet名称和单元格内容
            wb.setSheetName(0, "测试");

            String fileName = new String(("export-" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
                    .getBytes(), "UTF-8");
            response.setContentType("multipart/form-data");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
            response.setHeader("Pragma", "No-cache");
            response.setCharacterEncoding("utf-8");
            ServletOutputStream out = response.getOutputStream();
            wb.write(out);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}

ExcelService实现了导入导出功能的封装。导入功能无需多说,导出实现了读取模版,填充数据,以及对Excel 表格的一些合并,样式修改等功能~

最后,我们完成controller
ExcelController

package com.mrcoder.sbmexcel.controller;
import com.mrcoder.sbmexcel.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class ExcelController {
    @Autowired
    private ExcelService excelService;
    @PostMapping("/importExcel")
    public int importExcel(HttpServletRequest request) {
        return excelService.importExcel(request);
    }
    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response) {
        excelService.exportExcel(response);
    }
}

运行

http://localhost:8080/importExcel 导入
3.png

http://localhost:8080/exportExcel 导出
4.png

项目地址

https://github.com/MrCoderStack/SpringBootDemo/tree/master/sbm-excel

请关注我的订阅号

订阅号.png

Spring Boot进阶(07):如何使用EasyPoi实现Java中Excel的导入导出?完整教程请收藏,让你的Excel操作更高效! 集成EasyPoi,实现Excel的导入导出,一文教你学会。 阅读详情

相关推荐

基于SpringBoot的多线程实现快速导入EXCEL

前言:笔者已经做过多个版本的EXCEL导入功能。此次出一版基于SpringBoot的多线程实现快速导入EXCEL,效率之高体现在速度之快,单次解析的数据量之大。对比如下:第一版:导入5万条数据,花费近一个时第二版:导入10万条数据,花费23分钟,优化后达到了15分钟。第三版:导入112400条数据,花费3秒钟,极限是15万。数据再增大将会造成内存溢出。第三版:采用了多线程 1、不分服务,导入100万条数据,花费30秒之内。2、分服务,速度有所下降,80秒之内。效果图如下:注:导入数据速度跟数“量”的大小有关

LEN程序员的一生 7310

java代码实现excel数据导入数据库

1、添加POI jar包到项目的lib目录下­ 2、Excel文件目录:d://excel.xls­ 3、数据库字段为:num1 num2 num3 num4 num5 num6­ 4、数据库名:blog­ 5、表名:test­ 6、编写类:连接mysql的字符串方法、插入的方法、实体类­­ import java.io.FileInputStream;­ import java.io

王洋的专栏 1万+

Spring Boot进阶(09):用EasyPoi实现Excel多sheet导入导出,轻松管理海量数据!

集成EasyPoi,实现Excel文件多sheet的导入导出,一文教会大家。

**My Coding Family** 7400

excel数据导入

HSSFWorkbook wookbook = new HSSFWorkbook(new FileInputStream(fileTempPath));//创建工作簿的引用 HSSFSheet sheet = wookbook.getSheet("Sheet1"); //获取到Excel文件中的所有行数 int rows = sheet.getPhysicalNumberOfRo

NFA_YY的博客 378

tanner2019安装教程

tanner2019安装教程 tanner安装包 软件由老师提供,但由于老师给的方法不知怎么回事无法使用就自己找了一些方法,本教程仅提供参考 链接:https://pan.baidu.com/s/1A2O6JuEF8YFbe8bPnD3J6w 提取码:ysif 复制这段内容后打开百度网盘手机App,操作更方便哦 安装过程 1.选择TannerTools_v2019.2-Win64.exe,进行安装。 2.选择安装产品 3.选择目标路径 4.确认安装 5.安装成功,退出。 获取许可过程 1.打开key压缩

weixin_47730560的博客 1万+

ArcGIS实战:地形湿度指数(TWI)计算全流程解析

本文详细解析了ArcGIS中地形湿度指数(TWI)的计算全流程,从DEM数据获取、填洼处理到水流方向与汇流累积量计算,最终实现TWI的精准计算。通过实战步骤指导,帮助读者掌握水文建模和土壤湿度预测的关键技术,适用于农业规划、生态研究等领域。

weixin_29231725的博客 869

Spring-Boot-Starter快速实现Excel导入导出的方法

IT 果果为了满足项目中快速实现 excel 导入导出的功能,将 excel 开源工具 easypoi 整合成 spring-boot-starter 的方式,在做到对 easypoi 无侵入的同时减少了一些重复代码。例如:增强了 easypoi 对于字段值重复校验的功能;提升了字典转换的便捷性和效率;增加了字段之间联动转换的功能;

cz285933169的专栏 2007

WinCC动态选择报警记录案例

本例中需要确认查询的时间段以及查询的关键字,然后通过一个按钮来执行报警数据查询脚本,并把查询出的结果加载到当前报警控件中。<本例中数据查询脚本的思路是根据选项组所选定的参数加载相应的归档变量到在线趋势控件,根据设定的查询时间范围设定控件时间轴的开始时间及结束时间。本文以 WinCC V8.0为例,介绍如何动态的查询WinCC报警记录,包括关键字查询/时间&关键字查询,如图1所示。<在WinCC变量管理中创建不同的变量组,并在变量组下创建相应的变量,如图2 所示(下图并非实际变量值)。

weixin_45072604的博客 2708

SpringBoot实现Excel导入导出

SpringBoot实现Excel导入导出

YIYIYI 985

上交开源装甲板识别代码分析

GitHub - xinyang-go/SJTU-RM-CV-2019: 上海交通大学 RoboMaster 2019赛季 视觉代码这里着重分析主函数main.cpp与装甲板识别部分的工程文件armer文件夹。由于未完全分析,所以对于其中log.h、options.h中的函数并不清楚,在分析时会跳过这些内容。该文章重点分析的是思路,部分函数中的数学逻辑、数据处理思路这里不详细解释(没能力)所有思维导图通过 知犀知犀思维导图 - 知犀官网 (zhixi.com)原创。

qq_42104961的博客 1320

嵌入式内存管理之“LittleFS文件系统”开发(附LittleFS项目源码)

本文介绍了如何在嵌入式系统中实现 LittleFS 文件系统,并结合 Flash 存储进行数据管理。通过详细的代码示例,展示了如何配置、挂载 LittleFS 文件系统,并进行文件操作,如读取、写入和更新数据。特别地,博客通过实际应用演示了如何实现启动计数功能,以及如何处理文件系统的格式化和挂载过程。该示例帮助读者掌握在资源受限的嵌入式环境中实现高效文件存储管理的关键技术。

Bit_Dong的博客 3181

SpringBoot中使用Easyexcel实现Excel导入导出功能(一)

excel表格的导入与导出,可以说是业务系统里比较常见的功能了,早些时候相信很多人都是使用POI实现excel的导入与导出功能,后来出现了easyexcel,从我自己的使用感受来说,我更喜欢使用easyexcel,除了封装的比较好外,最重要的是对超级大excel导入有了更好的方案,与POI相比,速度更快,占用内存更少。

凡夫编程 2万+

操作系统实验一到实验九合集(哈工大李治军)

操作系统实验一到实验九合集(哈工大李治军) 有详细代码及注释,程序已在本地测试,均能跑通

leoabcd12的博客 5万+

SpringBoot 项目优雅实现 Excel 导入导出功能

点击上方关注 “终端研发部”设为“星标”,和你一起掌握更多数据库知识责编:架构君|来源:https://zzuhkp.blog.csdn.net/article/details/125097026上一篇好文:涉嫌简历造假,23届一位“offer大神”凉凉了!大家好,我是终端研发部小于哥。背景Excel 导入与导出是项目中经常用到的功能,在 Java 中常用 poi 实现 Excel 的导入与导...

这个时代,作为程序员可能要学习小程序 264

从零开始学习CANoe(六)—— CAPL 测试节点

创建CAPL Test Module的两种方式

蚂蚁小兵 1万+

基于Slim-Neck架构的YOLOv11轻量化特征融合方案(实现超轻量级与高精度的双重突破)

购买即可解锁800+YOLO优化文章,并且还有海量深度学习复现项目,价格仅需两杯奶茶的钱,每日更新。

m0_64661770的博客 250

SpringBoot2.x 整合 easyexcel 进行报表导入导出

【easyexcel简介】 阿里出品用来处理Excel的开源工具 为什么要使用 easyexcel ? Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。...

日拱一卒 1万+

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

项目实战--SpringBoot整合EasyExcel实现数据导入导出

在实际的业务开发过程中,根据参数动态实现 Excel 的导出导入应用是非常广的。

qq_40623672的博客 4214

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

springboot excel+mysql导入导出

excel数据的导入导出在开发中很常见,话不多说,直接开干 1.项目结构搭建 2.excel准备 3.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/200...

♨ 761

《SpringBoot》EasyExcel实现百万数据的导入导出

在日常的开发工作中,Excel 文件的读取和写入是非常常见的需求,特别是在后台管理系统中更为频繁,基于传统的方式操作excel通常比较繁琐,EasyExcel 库的出现为我们带来了更简单、更高效的解决方案。本文将介绍 EasyExcel 库的基本用法和一些常见应用场景,帮助开发者更好地利用 EasyExcel 提高工作效率。代码地址:https://github.com/alibaba/easyexcelEasy Excel 官网 (alibaba.com)

SevenCoding的博客 1396

SpringBoot从入门到精通教程(九): 集成EasyExcel 导入导出

【easyexcel简介】 阿里出品用来处理Excel的开源工具 为什么要使用 easyexcel ? Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,能够原本一个3M的excel用POI sax依然需要100M左右

程序员小刘 807

SpringBoot项目(java)使用注解进行excel导入、导出

在平时做项目的时候,经常在项目中有遇到excel导入、导出的功能,起初做在网上找了一些类似的demo,功能是实现了,但是总感觉代码量太大,而且不能够灵活的调用,每块功能需要调用的时候,都需要重新写一遍自己相关的字段信息,感觉非常不爽,于是结合网上和自己的理解写了基于注解进行Excel的导入、导出。 本次实现使用第三方jar包是poi 首先在maven项目中的pom文件中加入这个依赖包。 <dependency> <groupId>org.apache.po

YC是个程序员的博客 3892

SpringBoot: SpringBoot里面创建导出Excel的接口

在Web项目中,难免需要导出Excel这样的功能,后端接口怎么实现呢,Controller代码在下面,复制到项目的Controller中即可使用: 首先加入Excel的依赖,本例中我们用apache的poi: &amp;amp;amp;amp;amp;lt;dependency&amp;amp;amp;amp;amp;gt; &amp;amp;amp;amp;amp;lt;groupId&amp;amp;amp;amp;amp;gt;org.apache.poi

weixin_39448458的博客 4万+
上一篇: 22.从零开始学springboot-通用mapper的使用
下一篇: count(*)/count(1)/count(主键)统计效率对比
码哥说
博客等级 码龄8年 5645粉丝 172原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码哥说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值