当前位置:网站首页>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;
}
}
边栏推荐
- Summary of JFrame knowledge points 1
- 内核同步机制
- Width and widthstep of iplimage
- 博途V15添加GSD文件
- Exposure: a white box photo post processing framework reading notes
- 谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
- 我在中山,到哪里开户比较好?实际上网上开户安全么?
- 241. 为运算表达式设计优先级 : DFS 运用题
- Is it safe for Huatai Securities to open an account online?
- Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
猜你喜欢

Mechanism and type of CPU context switch

CPI tutorial - asynchronous interface creation and use

On recursion and Fibonacci sequence

Y48. Chapter III kubernetes from introduction to mastery -- pod status and probe (21)

redis配置环境变量

91. (cesium chapter) cesium rocket launch simulation

ACLY与代谢性疾病

91.(cesium篇)cesium火箭发射模拟

The Missing Semester

Interpretation of R & D effectiveness measurement framework
随机推荐
Value/sortedset in redis
使用set_handler过滤掉特定的SystemC Wraning &Error Message
241. Design priority for operational expressions: DFS application questions
Software project management 9.2 Software project configuration management process
Theoretical basis of graph
Can I open an account today and buy stocks today? Is it safe to open an account online?
Value/list in redis
构建外部模块(Building External Modules)
Building external modules
巩固-C#运算符
Use set_ Handler filters out specific SystemC wrapping & error messages
Binary stack (I) - principle and C implementation
我在中山,到哪里开户比较好?实际上网上开户安全么?
Summary of JFrame knowledge points 1
伸展树(一) - 概念和C实现
8 best practices to protect your IAC security!
ACLY与代谢性疾病
91.(cesium篇)cesium火箭發射模擬
今天开户今天能买股票吗?在线开户是很安全么?
Wechat applet development - user authorization to log in to "suggestions collection"