easyexcel解析跨多行的数据
在使用easyexcel解析excel文件的时候,存在某列横跨多行,那么存在解析出的对象的某些属性是没有值的,那么我们要怎么处理呢?代码如下
- 定义实体对应excel文件
public class EtcParkingReconciliationDailyImportModel implements Serializable {/** 创建时间 */private String insertTime = LocalDateTime.now().toString();/** 名称 */@ExcelProperty(index = 0)private String name;/** 清分交易 */@ExcelProperty(index = 2)private String clearingTransaction;/** 正常交易 */@ExcelProperty(index = 3)private String normalTransaction;/** 确认记账交易 */@ExcelProperty(index = 4)private String acknowledgeTransactions;/** 确认不记账交易 */@ExcelProperty(index = 5)private String confirmUntransactions;@ExcelProperty(index = 1)private String projectName;/*** 解析清分时间*/private String fillingTime;public String getProjectName() {return projectName;}public void setProjectName(String projectName) {this.projectName = projectName;}public String getFillingTime() {return fillingTime;}public void setFillingTime(String fillingTime) {this.fillingTime = fillingTime;}public EtcParkingReconciliationDailyImportModel() {}// Getter and Setter methods for insertTimepublic String getInsertTime() {return insertTime;}public void setInsertTime(String insertTime) {this.insertTime = insertTime;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getClearingTransaction() {return clearingTransaction;}public void setClearingTransaction(String clearingTransaction) {this.clearingTransaction = clearingTransaction;}public String getNormalTransaction() {return normalTransaction;}public void setNormalTransaction(String normalTransaction) {this.normalTransaction = normalTransaction;}public String getAcknowledgeTransactions() {return acknowledgeTransactions;}public void setAcknowledgeTransactions(String acknowledgeTransactions) {this.acknowledgeTransactions = acknowledgeTransactions;}public String getConfirmUntransactions() {return confirmUntransactions;}public void setConfirmUntransactions(String confirmUntransactions) {this.confirmUntransactions = confirmUntransactions;}}
- 创建Listener
public class EtcParkingReconciliationDailyExcelListener extends AnalysisEventListener<EtcParkingReconciliationDailyImportModel> {// 数据接收List<EtcParkingReconciliationDailyImportModel> dataList = Lists.newArrayList();// 头行数量int headNum = 1;List<String> temp = new ArrayList<String>();@Overridepublic void doAfterAllAnalysed(AnalysisContext arg0) {logger.info("EXCEL解析完成,共有数据:{}", dataList.size());}@Overridepublic void invoke(EtcParkingReconciliationDailyImportModel model, AnalysisContext context) {// 业务处理}public List<EtcParkingReconciliationDailyImportModel> getDataList() {return dataList;}// 重点是这个,获取跨列,行的数据记录,后面在反射的时候会用到private List<CellExtra> cellExtraList = new ArrayList<>();@Overridepublic void extra(CellExtra extra, AnalysisContext context) {CellExtraTypeEnum type = extra.getType();switch (type) {case MERGE: {if (extra.getRowIndex() >= headNum ) {cellExtraList.add(extra);}break;}default:{}}}public List<CellExtra> getCellExtraList() {return cellExtraList;}
- 定义方法解析跨列行的数据
/**
* excelDataList excel 解析出的数据
* cellExtraList 解析得到的跨行的数据
* headRowNum 头行数
*/private static void mergeExcelData(List<EtcParkingReconciliationDailyImportModel> excelDataList, List<CellExtra> cellExtraList, int headRowNum) {cellExtraList.forEach(cellExtra -> {int firstRowIndex = cellExtra.getFirstRowIndex() - headRowNum;int lastRowIndex = cellExtra.getLastRowIndex() - headRowNum;int firstColumnIndex = cellExtra.getFirstColumnIndex();int lastColumnIndex = cellExtra.getLastColumnIndex();//获取初始值Object initValue = getInitValueFromList(firstRowIndex, firstColumnIndex, excelDataList);//设置值for (int i = firstRowIndex; i <= lastRowIndex; i++) {for (int j = firstColumnIndex; j <= lastColumnIndex; j++) {setInitValueToList(initValue, i, j, excelDataList);}}});}private static void setInitValueToList(Object filedValue, Integer rowIndex, Integer columnIndex, List data) {EtcParkingReconciliationDailyImportModel object = (EtcParkingReconciliationDailyImportModel) data.get(rowIndex);for (Field field : object.getClass().getDeclaredFields()) {field.setAccessible(true);ExcelProperty annotation = field.getAnnotation(ExcelProperty.class);if (annotation != null) {if (annotation.index() == columnIndex) {try {field.set(object, filedValue);break;} catch (IllegalAccessException e) {e.printStackTrace();}}}}}private static Object getInitValueFromList(Integer firstRowIndex, Integer firstColumnIndex, List data) {Object filedValue = null;EtcParkingReconciliationDailyImportModel object = (EtcParkingReconciliationDailyImportModel) data.get(firstRowIndex);for (Field field : object.getClass().getDeclaredFields()) {field.setAccessible(true);ExcelProperty annotation = field.getAnnotation(ExcelProperty.class);if (annotation != null) {if (annotation.index() == firstColumnIndex) {try {filedValue = field.get(object);break;} catch (IllegalAccessException e) {e.printStackTrace();}}}}return filedValue;}
- 调用代码
// 根据自己的业务修改代码
File file = new File("");EtcParkingReconciliationDailyExcelListener listener = new EtcParkingReconciliationDailyExcelListener();EasyExcel.read(file, EtcParkingReconciliationDailyImportModel.class, listener)// 重点需要添加CellExtraTypeEnum.MERGE.extraRead(CellExtraTypeEnum.MERGE).sheet().headRowNumber(1).doRead();List<EtcParkingReconciliationDailyImportModel> dataList = listener.getDataList();// 调用mergeExcelData(dataList,listener.getCellExtraList(),3);dataList.forEach(System.out::println);
相关文章:
easyexcel解析跨多行的数据
在使用easyexcel解析excel文件的时候,存在某列横跨多行,那么存在解析出的对象的某些属性是没有值的,那么我们要怎么处理呢?代码如下 定义实体对应excel文件 public class EtcParkingReconciliationDailyImportModel implements S…...
双目相机立体匹配基础
双目匹配就是用左相机和右相机去拍摄同一个点,目的是找到三维世界的同一个点,也就是在左相机和右相机中的成像点之间的像素差(视差),根据视差去求解深度,那么找到左相机点到右相机的同一个对应点这个过程就…...
【图论】网络流
网络流目前只整理模板,学习的话这篇博客可能不太适合 代码参考下方博客,加了一些自己的注释 算法学习笔记(28): 网络流究级的最大流算法:ISAP与HLPP FF 和 EK 仅用作理解代码,赛时请使用 Dinic 或 ISAP 下文建图方式都基于链式…...
【Matplotlib】figure方法 你真的会了吗!?
🎈个人主页:甜美的江 🎉欢迎 👍点赞✍评论⭐收藏 🤗收录专栏:matplotlib 🤝希望本文对您有所裨益,如有不足之处,欢迎在评论区提出指正,让我们共同学习、交流进…...
[C++]继承(续)
一、基类和派生类对象赋值转换 在public继承时,父类和子类是一个“is - a”的关系。 子类对象赋值给父类对象/父类指针/父类引用,我们认为是天然的,中间不产生临时对象,也叫作父子类赋值兼容规则(切割/切片ÿ…...
恒创科技:服务器内存不足影响大吗?
服务器在为网站、应用程序和在线服务提供支持方面发挥着关键作用。这些服务器需要提供最佳性能,以确保正常无缝的用户体验,而RAM是显著影响服务器性能的关键配置之一。 RAM 是一种随机存取存储器,计算机和服务器使用它来临时存储正在使…...
深入理解网络通信和TCP/IP协议
目录 计算机网络是什么? 定义和分类 计算机网络发展简史 计算机网络体系结构 OSI 七层模型 TCP/IP 模型 TCP/IP 协议族 TCP/IP 网络传输中的数据 地址和端口号 MAC地址 IP 地址 端口号 为什么端口号有65535个? 综述 TCP 特性 TCP 三次握…...
Open CASCADE学习|分割曲线
1、通过参数进行分割 分别获得曲线的 FirstParameter 和 LastParameter ,然后对参数进行分割,获得n个ui,并对每个ui调用D0(获得这个点的坐标值)或D1(获得这个点的坐标值和切向量)。这个方法的优…...
vulhub中Adminer远程文件读取漏洞复现(CVE-2021-43008)
Adminer是一个PHP编写的开源数据库管理工具,支持MySQL、MariaDB、PostgreSQL、SQLite、MS SQL、Oracle、Elasticsearch、MongoDB等数据库。 在其版本1.12.0到4.6.2之间存在一处因为MySQL LOAD DATA LOCAL导致的文件读取漏洞。 参考链接: https://gith…...
MOS管驱动电流估算-Qg参数
MOS管驱动电流估算 例:FDH45N50F如下参数: 有人可能会这样计算: 开通电流 带入数据得 关断电流 带入数据得 于是乎得出这样的结论,驱动电流只需 250mA左右即可。仔细想想这样计算对吗? 这里必须要注意这样一个条件细…...
Vision Transfomer系列第一节---从0到1的源码实现
本专栏主要是深度学习/自动驾驶相关的源码实现,获取全套代码请参考 这里写目录标题 准备逐步源码实现数据集读取VIt模型搭建hand类别和位置编码类别编码位置编码 blocksheadVIT整体 Runner(参考mmlab)可视化 总结 准备 本博客完成Vision Transfomer(VIT)模型的搭建和flowers数…...
【CSS + ElementUI】更改 el-carousel 指示器样式且隐藏左右箭头
需求 前三条数据以走马灯形式展现,指示器 hover 时可以切换到对应内容 实现 <template><div v-loading"latestLoading"><div class"upload-first" v-show"latestThreeList.length > 0"><el-carousel ind…...
Ubuntu 22.04 上安装和使用 Go
1.下载 All releases - The Go Programming Language //https://golang.google.cn/dl/wget https://golang.google.cn/dl/go1.21.6.linux-amd64.tar.gz 2.在下载目录下执行,现在,使用以下命令将文件提取到 “/usr/local ” 位置 sudo tar -C /usr/…...
ES6-const
一、基本用法 - 语法:const 标识符初始值;注意:const一旦声明变量,就必须立即初始化,不能留到以后赋值 - 规则:1.const 声明一个只读的常量,一旦声明,常量的值就不能改变2.const 其实保证的不是变量的值不…...
Android消息通知Notification
Notification 发送消息接收消息 #前言 最近在做消息通知类Notification的相关业务,利用闲暇时间总结一下。主要分为两部分来记录:发送消息和接收消息。 发送消息 发送消息利用NotificationManager类的notify方法来实现,现用最普通的方式发…...
2V2无人机红蓝对抗仿真
两架红方和蓝方无人机分别从不同位置起飞,蓝方无人机跟踪及击毁红方无人机 2020a可正常运行 2V2无人机红蓝对抗仿真资源-CSDN文库...
VUE3语法--computed计算属性中get和set使用案例
1、功能概述 计算属性computed是Vue3中一个响应式的属性,最大的用处是基于多依赖时的监听。也就是属性A的值可以根据其他数据的变化而响应式的变化。 在Vue3中,你可以使用computed函数来定义计算属性。computed函数接收两个参数:一个包含getter和setter函数的对象和可选的…...
Linux cd 和 df 命令执行异常
这篇记录一些奇奇怪怪的命令执行异常的情况,后续有新的发现也会补录进来 情况一 /tmp 目录权限导致 按 tab 补充报错 情况描述 cd 按 tab 自动补充文件报错(普通用户) bash: cannot create temp file for here-document: Permission denie…...
【计算机网络】物理层概述|通信基础|奈氏准则|香农定理|信道复用技术
目录 一、思维导图 二、 物理层概述 1.物理层概述 2.四大特性(巧记"械气功程") 三、通信基础 1.数据通信基础 2.趁热打铁☞习题训练 3.信号の变身:编码与调制 4.极限数据传输率 5.趁热打铁☞习题训练 6.信道复用技术 推荐 前些天发…...
XXE基础知识整理(附加xml基础整理)
全称:XML External Entity 外部实体注入攻击 原理 利用xml进行读取数据时过滤不严导致嵌入了恶意的xml代码;和xss原理雷同 危害 外界攻击者可读取商户服务器上的任意文件; 执行系统命令; 探测内网端口; 攻击内网网站…...
Python爬虫实战:研究MechanicalSoup库相关技术
一、MechanicalSoup 库概述 1.1 库简介 MechanicalSoup 是一个 Python 库,专为自动化交互网站而设计。它结合了 requests 的 HTTP 请求能力和 BeautifulSoup 的 HTML 解析能力,提供了直观的 API,让我们可以像人类用户一样浏览网页、填写表单和提交请求。 1.2 主要功能特点…...
多云管理“拦路虎”:深入解析网络互联、身份同步与成本可视化的技术复杂度
一、引言:多云环境的技术复杂性本质 企业采用多云策略已从技术选型升维至生存刚需。当业务系统分散部署在多个云平台时,基础设施的技术债呈现指数级积累。网络连接、身份认证、成本管理这三大核心挑战相互嵌套:跨云网络构建数据…...
安宝特方案丨XRSOP人员作业标准化管理平台:AR智慧点检验收套件
在选煤厂、化工厂、钢铁厂等过程生产型企业,其生产设备的运行效率和非计划停机对工业制造效益有较大影响。 随着企业自动化和智能化建设的推进,需提前预防假检、错检、漏检,推动智慧生产运维系统数据的流动和现场赋能应用。同时,…...
UDP(Echoserver)
网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法:netstat [选项] 功能:查看网络状态 常用选项: n 拒绝显示别名&#…...
Robots.txt 文件
什么是robots.txt? robots.txt 是一个位于网站根目录下的文本文件(如:https://example.com/robots.txt),它用于指导网络爬虫(如搜索引擎的蜘蛛程序)如何抓取该网站的内容。这个文件遵循 Robots…...
学习STC51单片机32(芯片为STC89C52RCRC)OLED显示屏2
每日一言 今天的每一份坚持,都是在为未来积攒底气。 案例:OLED显示一个A 这边观察到一个点,怎么雪花了就是都是乱七八糟的占满了屏幕。。 解释 : 如果代码里信号切换太快(比如 SDA 刚变,SCL 立刻变&#…...
Redis的发布订阅模式与专业的 MQ(如 Kafka, RabbitMQ)相比,优缺点是什么?适用于哪些场景?
Redis 的发布订阅(Pub/Sub)模式与专业的 MQ(Message Queue)如 Kafka、RabbitMQ 进行比较,核心的权衡点在于:简单与速度 vs. 可靠与功能。 下面我们详细展开对比。 Redis Pub/Sub 的核心特点 它是一个发后…...
服务器--宝塔命令
一、宝塔面板安装命令 ⚠️ 必须使用 root 用户 或 sudo 权限执行! sudo su - 1. CentOS 系统: yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh2. Ubuntu / Debian 系统…...
七、数据库的完整性
七、数据库的完整性 主要内容 7.1 数据库的完整性概述 7.2 实体完整性 7.3 参照完整性 7.4 用户定义的完整性 7.5 触发器 7.6 SQL Server中数据库完整性的实现 7.7 小结 7.1 数据库的完整性概述 数据库完整性的含义 正确性 指数据的合法性 有效性 指数据是否属于所定…...
MFC 抛体运动模拟:常见问题解决与界面美化
在 MFC 中开发抛体运动模拟程序时,我们常遇到 轨迹残留、无效刷新、视觉单调、物理逻辑瑕疵 等问题。本文将针对这些痛点,详细解析原因并提供解决方案,同时兼顾界面美化,让模拟效果更专业、更高效。 问题一:历史轨迹与小球残影残留 现象 小球运动后,历史位置的 “残影”…...
