当前位置:网站首页>easyexcel的使用
easyexcel的使用
2022-07-01 11:56:00 【qq_46198929】

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apche.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
package com.example.demo.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class DemoData {
//设置excel表头名称
@ExcelProperty(value = "学生编号",index = 0)
private Integer sno;
@ExcelProperty(value = "学生姓名",index = 1)
private String sname;
}
package com.example.demo.excel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import java.util.Map;
public class ExcelListener extends AnalysisEventListener<DemoData> {
//一行一行读取excel内容
@Override
public void invoke(DemoData data, AnalysisContext analysisContext) {
System.out.println("****"+data);
}
//读取表头内容
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
System.out.println("表头:"+headMap);
}
//读取完成之后
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}
package com.example.demo.excel;
import com.alibaba.excel.EasyExcel;
import java.util.ArrayList;
import java.util.List;
public class TestEasyExcel {
public static void main(String[] args) {
//实现excel写的操作
//1 设置写入文件夹地址和excel文件名称
//String filename = "D:\\write.xlsx";
//2 调用easyexcel里面的方法实现写操作
//write方法两个参数:第一个参数文件路径名称,第二个参数实体类class
//EasyExcel.write(filename,DemoData.class).sheet("学生列表").doWrite(getData());
//实现excel读操作
String filename = "D:\\write.xlsx";
EasyExcel.read(filename,DemoData.class,new ExcelListener()).sheet().doRead();
}
//创建方法返回list集合
private static List<DemoData> getData() {
List<DemoData> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
DemoData data = new DemoData();
data.setSno(i);
data.setSname("lucy"+i);
list.add(data);
}
return list;
}
}
边栏推荐
- Matrix of numpy
- Uniapp uses uni upgrade Center
- Exposure: a white box photo post processing framework reading notes
- Understanding of MVVM and MVC
- The Missing Semester
- 我在中山,到哪里开户比较好?实际上网上开户安全么?
- Comment Cao définit la décimale de dimension
- GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
- [classic example] classic list questions @ list
- C knowledge point form summary 2
猜你喜欢

Joint Time-Frequency and Time Domain Learning for Speech Enhancement

Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation

技术分享 | MySQL:从库复制半个事务会怎么样?

GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021

邻接矩阵无向图(一) - 基本概念与C语言
![[Maui] add click events for label, image and other controls](/img/d6/7ac9632681c970ed99c9e4d3934ddc.jpg)
[Maui] add click events for label, image and other controls

2022/6/30学习总结

CPU 上下文切换的机制和类型 (CPU Context Switch)

Abbirb120 industrial robot mechanical zero position

图的理论基础
随机推荐
91.(cesium篇)cesium火箭发射模拟
Width and widthstep of iplimage
Wechat applet development - user authorization to log in to "suggestions collection"
Activity workflow engine
How to make the development of liquidity pledge mining system, case analysis and source code of DAPP defi NFT LP liquidity pledge mining system development
图的理论基础
[Maui] add click events for label, image and other controls
Golang根据参数引入相应配置文件的实现方式
Learning summary on June 30, 2022
NOV Schedule for . Net to display and organize appointments and recurring events
华为HMS Core携手超图为三维GIS注入新动能
Can solo be accessed through IPv6?
Skip the test cases to be executed in the unittest framework
指纹浏览器工作原理、使用场景以及重要性简单讲解
[MCU] [nixie tube] nixie tube display
使用set_handler过滤掉特定的SystemC Wraning &Error Message
ES6 promise Usage Summary
redis中value/hush
迅为i.MX8Mmini开发板离线构建Yocto系统
Emotion analysis based on IMDB comment data set