当前位置:网站首页>jg_使用easyexcel读取excel_20220619
jg_使用easyexcel读取excel_20220619
2022-06-22 10:08:00 【qq_40711092】
依赖
<!--easyexcel-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
实体类
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
/** * 表格实体 */
public class ExcelMode extends BaseRowModel {
/** * 第一列的数据 */
@ExcelProperty(index = 0)
private String column1;
/** * 第二列的数据 */
@ExcelProperty(index = 1)
private String column2;
/** * 第六列的数据 */
@ExcelProperty(index = 5)
private String column6;
public String getColumn6() {
return column6;
}
public void setColumn6(String column6) {
this.column6 = column6 +"日";
}
public void setColumn1(String column1) {
this.column1 = column1;
}
public String getColumn1() {
return column1;
}
public String getColumn2() {
return column2;
}
public void setColumn2(String column2) {
this.column2 = column2;
}
@Override
public String toString() {
return "ExcelMode{" +
"column1='" + column1 + '\'' +
", column2='" + column2 + '\'' +
'}';
}
}
代码
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.metadata.Sheet;
import com.dxy.demo_05_08.bean.easyExc.ExcelMode;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class EasyRead {
// 简单读取 (同步读取)
public static void simpleRead() {
// 读取 excel 表格的路径
String readPath = "E:\\other\\ceshi.xlsx";
try {
// sheetNo --> 读取哪个 表单
// headLineMun --> 从哪一行开始读取( 不包括定义的这一行,好比 headLineMun为2 ,那么取出来的数据是从 第三行的数据开始读取 )
// clazz --> 将读取的数据,转化成对应的实体,须要 extends BaseRowModel
Sheet sheet = new Sheet(1, 1, ExcelMode.class);
// 这里 取出来的是 ExcelModel实体 的集合
List<Object> readList = EasyExcelFactory.read(new FileInputStream(readPath), sheet);
// 存 ExcelMode 实体的 集合
List<ExcelMode> list = new ArrayList<ExcelMode>();
for (Object obj : readList) {
list.add((ExcelMode) obj);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
simpleRead();
}
}
参考文章
边栏推荐
- Solend废止「接管巨鲸」提案 清算「炸弹」未除
- Force buckle 1108 IP address invalidation
- 三个月让软件项目成功“翻身”!
- HMS Core新闻行业解决方案:让技术加上人文的温度
- 《网络安全等级保护基本要求》(GBT 22239-2019)标准解读
- MySQL skip scan range small function to solve big problems?
- Target detection / segmentation training using pytorch mask RCNN
- 10-2xxe vulnerability principle and case experiment demonstration
- 大学生期末考试SQL语句
- Tiktok practice ~ one click registration and login process of mobile phone number (verification code)
猜你喜欢

Should the theme of the IDE be bright or dark? Here comes the ultimate answer!

AttributeError: module ‘skimage. draw‘ has no attribute ‘circle‘

Attack and defense world web practice area beginner level

扎克伯格最新VR原型机来了,要让人混淆虚拟与现实的那种

Read the history of it development in one breath

Cobalt strike from entry to imprisonment (III)

Introduction to code audit learning notes
![[untitled] repair log](/img/8c/e05098c3731b4efce270108d6c52a7.png)
[untitled] repair log

使用 Matplotlib 这么久,竟不知道数据可以动起来

10-2xxe漏洞原理和案例实验演示
随机推荐
命令行下获取公网IP地址汇总
力扣 1108. IP 地址无效化
[untitled] repair log
IPO Configuration Guide
2022-06-09 work record --yarn/npm-error-eperm: operation not permitted, UV_ cwd
C language to write a two-way linked list
Software project management 8.3 Agile project quality activities
《网络安全等级保护基本要求》(GBT 22239-2019)标准解读
信号完整性(SI)电源完整性(PI)学习笔记(二十四)差分对与差分阻抗(四)
thinkphp3.2.3日志包含分析
拉开安全距离:国际空间站采取了主动避让太空垃圾碎片的措施
【深度学习】不得了!新型Attention让模型提速2-4倍!
Kali uses the command ifconfig to query the solution that the IP address is always 127.0.0.1
thinkphp5.0.24反序列化漏洞分析
符合我公司GIS开源解决方案的探讨
From in MySQL_ Unixtime and UNIX_ Timestamp processing database timestamp conversion - Case
PAT甲级 - 1015 Reversible Primes (进制转换&素数判断)
信息系统项目典型生命周期模型
IDE 的主题应该用亮色还是暗色?终极答案来了!
Catch up with this big guy