EasyExcel实现批量导入

java之poi 使用 easyexcel 实现Excel 批量导入导出 本章提供了java使用阿里的easyexcel实现Excel导入,导出示例,还有网络下载的方法。 模板大家可以随意制作,本例中使用模板表头及数据已经截图,以供参考。 easyexcel背景: Java解析,生成Excel比较有名的框架有Apache poi,jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一... 阅读详情

EasyExcel代码及官方文档:https://github.com/alibaba/easyexcel

最近项目中遇到需要Excel导入数据的情况,由于几十万条的数据量过大,再加上逻辑处理比较多,最初采用poi导入,占用资源过大,导入过程中服务器内存几乎100%占用,耗时较久,因此更换为EasyExcel。实测效果确实立竿见影,效率至少提升一倍,在这里把代码贴上,不足之处欢迎指正。

1导入jar包

先到mvn上搜索依赖包,引入pom中,下面是最新的

		<!--easyexcel-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>1.1.2-beat1</version>
        </dependency>

2创建模型

实际使用中,我认为创建模型时相对快捷而且不容易出错的方式,可以通过String类型接收数据后,自己再转换类型,防止类型转换错误。


import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;

import java.io.Serializable;

@Data
@Builder
public class JmmImport extends BaseRowModel implements Serializable {

    @Tolerate
    public JmmImport(){}

    /**
     * 门店编码
     */
    @ExcelProperty(value ="门店编码",index = 0)
    private String storeCode;
    /**
     * 商品编码
     */
    @ExcelProperty(value ="商品编码",index = 1)
    private String goodsCode;

    /**
     * 商品名称
     */
    @ExcelProperty(value ="商品名称",index = 2)
    private String goodsName;
    /**
     * 商品品类code
     */
    @ExcelProperty(value ="商品品类code",index = 3)
    private String goodsClassCode;
    /**
     * 商品属性code
     */
    @ExcelProperty(value ="商品属性code",index = 4)
    private String goodsAttrCode;
    /**
     * 档期起始时间
     */
    @ExcelProperty(value ="档期起始时间",index = 5)
    private String beginTime;
    /**
     * 档期结束时间
     */
    @ExcelProperty(value ="档期结束时间",index = 6)
    private String overTime;
}

3正式导入

List<Object>  objs = EasyExcelFactory.read(multipartFile.getInputStream(), new com.alibaba.excel.metadata.Sheet(1, 1,JmmImport.class));
        List<JmmDetailSold> excelList = Lists.newArrayList();
        for (Object o : objs) {
            if (o instanceof JmmImport) {
                JmmDetailSold excel = JmmDetailSold.builder()
                        .storeCode(((JmmImport) o).getStoreCode())
                        .goodsCode(((JmmImport) o).getGoodsCode())
                        .goodsName(((JmmImport) o).getGoodsName())
                        .goodsClassCode(((JmmImport) o).getGoodsClassCode())
                        .goodsAttrCode(((JmmImport) o).getGoodsAttrCode())
                        .beginTime(Timestamp.valueOf(((JmmImport) o).getBeginTime()))
                        .overTime(Timestamp.valueOf(((JmmImport) o).getOverTime()))
                        .build();
                excelList.add(excel);
            }
        }
vue+spring boot项目实现EasyExcel批量导入 一、先来了解一下EasyExcel: 1、Poi和EasyExcel框架都能生成excel,但是poi框架非常耗内存,因此推荐使用easyexcel生成excel。EasyExcel是阿里巴巴开源的一个excel处理框架,easyexcel能够减少内存的消耗的主要原因是,在解析Excel时没有将文件数据一次性全部加载到内存中,而是从磁盘上一行行读取数据,逐个解析。 2、EasyExcel导入使用的场景:减轻录入工作量 二、vue前端代码实现 调用vue element-ui官网(https://elemen 阅读详情

相关推荐

EasyExcel+线程池+批量插入实现百万级数据导入:从原理到实战的完整指南

本文介绍了一种高效处理百万级数据导入的优化方案,通过结合EasyExcel流式读取、线程池并发处理和JDBC批量插入技术,将传统单线程逐条插入方式从小时级优化到分钟级。方案采用生产者-消费者模式,使用阻塞队列作为数据缓冲区,通过线程池实现并行处理,并采用批量插入方式减少数据库交互次数。文中详细展示了核心实现代码,包括数据实体类、导入服务类、Controller层实现及数据库优化配置,并提供了性能测试数据(100万条数据从4500秒优化到195秒)。同时针对常见问题(内存溢出、连接池耗尽、数据重复等)给出了解

longgelaile的博客 690

EasyExcel的jar包 和 使用

easyexcel的jar包资源

weixin_72979483的博客 4612

SpringBoot整合EasyExcel+MyBatis-Plus实现Excel批量导入和导出

使用EasyExcel实现批量导入和导出

李长渊的博客 1万+

easyExcel的简单使用

【代码】easyExcel的简单使用。

weixin_45441597的博客 1172

easyExcel所需jar包

easyExcel所需jar包

easyexcel处理jar包

ava解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,能够原本一个3M的excel用POI sax依然需要100M左右内存降低到KB级别,并且再大的excel不会出现内存溢出,03版依赖POI的sax模式。在上层做了模型转换的封装,让使用者更加简单方便

easyexcel实现批量导入

6. 控制器 UserController.java。5. 服务层 UserService.java。

Kunjpg的博客 640

easyexcel需要的jar.zip

webproject 使用easyexcel 需要放进bin的jar包

JAVA实现easyExcel批量导入

注解 类型 描述 ExcelProperty 导入 指定当前字段对应excel中的那一列。可以根据名字或者Index去匹配。当然也可以不写,默认第一个字段就是index=0,以此类推。千万注意,要么全部不写,要么全部用index,要么全部用名字去匹配。千万别三个混着用,除非你非常了解源代码中三个混着用怎么去排序的。 ExcelIgnore 导入 默认所有字段都会和excel去匹配,加了这个注解会忽略该字段 DateTimeFormat 导入 日期转换,用String去接收excel日

m0_46300599的博客 3947

WSL2离线安装Ubuntu终极指南:绕过Microsoft Store慢速下载(附最新22.04 LTS离线包)

本文提供WSL2离线安装Ubuntu 22.04 LTS的完整指南,帮助开发者绕过Microsoft Store下载慢的问题。通过PowerShell命令配置环境、获取离线安装包并完成安装,同时包含初始配置、资源优化及常见问题解决方案,助您快速搭建高效的Linux开发环境。

c8d9e0f1的博客 899

别再只用LSTM了!用Temporal Fusion Transformer (TFT) 搞定多变量时序预测,附PyTorch实战代码

本文介绍了Temporal Fusion Transformer (TFT) 在多变量时序预测中的优势,并提供了PyTorch实战代码。TFT通过三重注意力机制解决了LSTM在特征交互、静态特征处理和解释性方面的不足,显著提升了预测精度和可解释性。文章详细讲解了TFT的核心组件构建、数据预处理、模型训练技巧及可解释性分析,帮助开发者快速掌握这一先进时序预测技术。

weixin_33712987的博客 279

EasyExcel实现批量导入数据库

EasyExcel实现定制化,高效读取Excel文件内容

程序员Forlan的博客 1729

抖音短视频数据抓取实战系列(一)——模拟器性能对比与优化配置

本文是抖音短视频数据抓取实战系列的开篇,重点探讨了模拟器选型与优化配置。通过对比雷电、夜神、逍遥三大主流模拟器在性能、抖音兼容性及抓包友好度上的表现,文章指出雷电模拟器因其稳定的桥接网络模式和良好的兼容性,是数据抓取的优选。并提供了雷电模拟器从安装、网络桥接到系统优化的详细配置指南,旨在帮助读者构建稳定高效的抓取环境。

weixin_29230901的博客 246

SpringBoot+EasyExcel+Mybatis-plus实现通用Excel数据批量导入

基于java实现的快捷、简洁、解决大文件内存溢出(即OOM)不用考虑性能、内存等因素情况下,快速完成Excel的读、写等功能。从简介中,知道使用EasyExcel操作Excel时,我们只需要关注业务本身即可。

jiashn123的专栏 2349

Hermes+MemOS记忆系统:用SQLite构建可编辑AI个人认知资产

AI记忆不是简单延长上下文或叠加RAG,而是构建具备分层存储、混合检索与自然语言反馈能力的个人认知资产。其核心原理在于将用户交互痕迹(L1)、偏好策略(L2)、结构化世界模型(L3)和结晶化技能统一管理,实现记忆的可追溯、可修正、可进化。技术价值体现在降低token消耗、提升长程一致性、支持离线演进,并突破传统‘静态快照’式知识库局限。典型应用场景包括个人知识助手、客服工单分析Agent、研发文档理解系统等。本文聚焦Hermes Agent与MemOS深度集成方案,详解SQLite作为ACID底座支撑L1/

weixin_33623304的博客 434

【保姆级教程】基于UNet++&MobileNetv2的语义分割模型从训练到RK3588部署:让边缘AI落地效率提升300%

通过SMP库一键构建encoder_name="mobilenet_v2", # 选择MobileNetv2作为骨干encoder_weights="imagenet", # 加载预训练权重加速收敛in_channels=3, # 输入图像通道数(RGB)classes=29, # Cityscapes数据集类别数activation=None # 输出无激活,便于后续损失计算本教程从“模型设计-训练-转换-边缘部署”全链路拆解了。

FJN110的博客 210

SpringBoot实现Excel导入:从EasyExcel到批量入库的完整方案

在企业后台系统中,Excel导入是高频需求,但面对大数据量、脏数据、格式不一致等问题,简单的文件上传加循环插入往往导致内存溢出或事务失控。理解SAX流式解析原理,才能从根本上解决性能瓶颈;配合批量插入和合理的事务边界,可以大幅提升导入吞吐量。基于SpringBoot和EasyExcel,从Controller接口到监听器逐行校验,再到批量落库,形成一套可落地的工程实践。通过引入rewriteBatchedStatements优化MySQL批量写入,结合异步任务与进度反馈,可应对几十万行的数据量;同时处理日期

weixin_34253126的博客 464

【异常】OpenClaw报错 400 Total tokens of image and text exceed max message tokens. Request

OpenClaw报错400(Token超限)解决方案摘要 该报错因文本/图片总Token数超过模型限额导致,常见于多轮对话累积或单次请求过大。提供三级解决方案: 应急处理:输入"/new"指令清空会话历史,立即重置Token计数(90%问题可解决) 折中方案:保留历史对话前提下,通过精简当前输入、删除早期无关对话或拆分请求来压缩Token 专属处理:单次请求超限时,拆分长文本为2000字以内段落,或分批次上传降低分辨率图片 长期预防建议定期使用"/new"开启新会话,

奶爸的编程之路,也就一周冷个三天 1390

基于 EasyExcel + 线程池 + 批量插入实现百万级数据导入

项目中有一个数据迁移,原来的数据存储在旧的系统,现在系统做了重构,需要迁移到新的系统中,老系统的数据被加工到Excel中了,需要基于Excel实现文件的导入,同时需要避免内存溢出以及性能太低的问题。

lijianhua的博客 303

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信

优秀的 Verilog/FPGA开源项目介绍(一)-PCIe通信今天开始会陆续介绍一些优秀的开源项目,项目基本都是和FPGA或HDL相关的。对于一些找工作或者急需项目经验的人来说,这些项目...

OpenFPGA的博客 8117

建行报专版报道建设银行金融科技发展历程

经过十多年的建设,总行前中后台部门都有了自己的业务系统,但系统“部门”特征显著,渠道、客户、产品的横向整合不足,产品系统层次化、结构化、参数化程度不高,渠道支持产品快速部署以及跨渠道服务能力不足,管理分析类系统建设相对滞后,系统较弱的可扩展能力在应对高速增长的交易量时已疲态尽显,同时安全稳定运行的压力和风险日益积聚。站在新的历史起点上,科技条线将聚焦主责主业,完善信息科技管理体系,紧紧围绕安全生产中心任务,持续推动技术能力复用共享和自主可控,为全行做好金融五篇大文章,推动业务高质量发展提供技术支撑。

银行信息系统应用架构详解 385

Springboot项目实现easyExcel批量导入到数据库

在service中为了返回详细的错误提示,在读取数据之前,先将存储错误信息的list以set的形式给初始化;在数据插入结束之后调用listener中的函数返回错误信息。对数据的插入部分我写到了listener中,也可以写到Service中。若是项目中没有配置swagger不需要写。

qq_53844452的博客 818

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot 整合阿里EasyExcel实现表格批量导入

springBoot 整合easyExcel 实现业务逻辑

qxl288882的博客 1293

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Java使用EasyExcel实现批量导入

EasyExcel是阿里下的开源产品,基于poi进行的开发,相比于其他的解析方式不要太6。接下来就是使用的方式 第一步:引入jar包 <!--easyexcel解析excell--> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexce...

qq_35771266的博客 7330

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: JAVA foreach和普通for循环是否需要判断为null
下一篇: Spring Boot程序 向其他API接口发送Http请求并接收返回结果
马匠
博客等级 码龄7年 3粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值