当前位置:网站首页>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;
}
}
边栏推荐
- How does Nike dominate the list all the year round? Here comes the answer to the latest financial report
- C summary of knowledge points 1
- 二叉堆(一) - 原理与C实现
- 91. (chapitre Cesium) simulation de lancement de fusées cesium
- NOV Schedule for . Net to display and organize appointments and recurring events
- redis中value/list
- Build yocto system offline for i.mx8mmini development board
- S7-1500plc simulation
- Redis启动与库进入
- LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
猜你喜欢
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
How to understand the developed query statements
CAD如何设置标注小数位
CPI tutorial - asynchronous interface creation and use
Redis' attack tactics
GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021
[classic example] classic list questions @ list
C knowledge point form summary 2
Adjacency matrix undirected graph (I) - basic concepts and C language
91. (chapitre Cesium) simulation de lancement de fusées cesium
随机推荐
Botu V15 add GSD file
2022/6/30学习总结
CPU 上下文切换的机制和类型 (CPU Context Switch)
Emotion analysis based on IMDB comment data set
Epoll introduction
Golang des-cbc
On recursion and Fibonacci sequence
基于IMDB评论数据集的情感分析
我在中山,到哪里开户比较好?实际上网上开户安全么?
Personnaliser le plug - in GRPC
Golang introduces the implementation method of the corresponding configuration file according to the parameters
2022/6/29学习总结
Talk about biological live broadcast - genovis Zhang Hongyan antibody specific enzyme digestion technology helps to characterize the structure of antibody drugs
巩固-C#运算符
Value/list in redis
I'm in Zhongshan. Where is a better place to open an account? Is it actually safe to open an account online?
Impressive bug summary (continuously updated)
指定的服务已标记为删除
Harbor webhook from principle to construction
Redis' attack tactics