当前位置:网站首页>Use of easyexcel
Use of easyexcel
2022-07-01 12:03:00 【qq_ forty-six million one hundred and ninety-eight thousand nin】

<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 {
// Set up excel Header name
@ExcelProperty(value = " Student number ",index = 0)
private Integer sno;
@ExcelProperty(value = " The student's name ",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> {
// Read line by line excel Content
@Override
public void invoke(DemoData data, AnalysisContext analysisContext) {
System.out.println("****"+data);
}
// Read the contents of the header
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
System.out.println(" Header :"+headMap);
}
// After the read is complete
@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) {
// Realization excel The operation of writing
//1 Set the write folder address and excel File name
//String filename = "D:\\write.xlsx";
//2 call easyexcel The method inside realizes the write operation
//write Method two parameters : First parameter file path name , Second parameter entity class class
//EasyExcel.write(filename,DemoData.class).sheet(" Student list ").doWrite(getData());
// Realization excel Read operations
String filename = "D:\\write.xlsx";
EasyExcel.read(filename,DemoData.class,new ExcelListener()).sheet().doRead();
}
// The creation method returns list aggregate
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;
}
}
边栏推荐
- Joint Time-Frequency and Time Domain Learning for Speech Enhancement
- C knowledge point form summary 2
- Wechat applet development - user authorization to log in to "suggestions collection"
- 2022/6/29学习总结
- Seckill system 03 - redis cache and distributed lock
- Value/hush in redis
- 自组织是管理者和成员的双向奔赴
- Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
- [classic example] classic list questions @ list
- 基于IMDB评论数据集的情感分析
猜你喜欢

Binary stack (I) - principle and C implementation

Deep understanding of grpc part1

Uniapp uses uni upgrade Center

Learning summary on June 29, 2022

Compile and debug net6 source code

Emotion analysis based on IMDB comment data set

华为HMS Core携手超图为三维GIS注入新动能

uniapp 使用 uni-upgrade-center

Redis的攻击手法

Le semester manquant
随机推荐
Raspberry pie 4B installation tensorflow2.0[easy to understand]
Redis' attack tactics
91. (chapitre Cesium) simulation de lancement de fusées cesium
S7-1500plc simulation
Want to ask, is there a discount for opening a securities account? Is it safe to open a mobile account?
leetcode 406. Queue Reconstruction by Height(按身高重建队列)
sshd_ Discussion on permitrotlogin in config
耐克如何常年霸榜第一名?最新財報答案來了
Custom grpc plug-in
Value/list in redis
证券账户销户后果 开户安全吗
241. Design priority for operational expressions: DFS application questions
C knowledge point form summary 2
Exposure: a white box photo post processing framework reading notes
uniapp 使用 uni-upgrade-center
Activity workflow engine
JS date format conversion method
Golang introduces the implementation method of the corresponding configuration file according to the parameters
Adjacency matrix undirected graph (I) - basic concepts and C language
Value/sortedset in redis