当前位置:网站首页>POI and easyexcel exercises
POI and easyexcel exercises
2022-04-23 06:21:00 【Excellent face】
Talk about POI and easyExcel
In development, we often need to excel To deal with , For example, export Excel form ,Excel The data in the table is written to the database !
operation Excel What's more popular at present is POI and easyExcel !
Project source code :https://github.com/yan418/poi
Bloggers focus on :http://goodysr.cn
POI
Construction works
Need to guide package :
<!-- poi The batch operation -Excel -->
<!-- xls(03)-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!--xlsx(07)-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
POI project , The specific operation depends on the project source code , The source code is on it .
Address :https://github.com/yan418/poi
EasyExcel
EasyExcel Official website address :https://github.com/alibaba/easyexcel
Need to guide package :
<!-- alibaba Of EasyExcel - Excel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
EasyExcel The operation of
You need to add corresponding comments to the entity class @ExcelProperty(“ String title ”)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
@ExcelProperty("ID value ")
private Integer id;
// user name
@ExcelProperty(" user name ")
private String username;
// Real name
@ExcelProperty(" Real name ")
private String realName;
...
}
EasyExcel Import Excel
// EasyExcel Import Excel
// 1. Entity class Add to each field @ annotation @ExcelProperty
@Test
void testWrite() throws Exception{
// List Entity class data
List<User> user = userDao.getUser();
// How to write it 1 write in Excel
String fileName = path + "EasyExcel.xlsx";
// here You need to specify which class To write , Then write the first one sheet, The name is template Then the file stream will close automatically
// If you want to use 03 be Pass in excelType Parameters can be
EasyExcel.write(fileName, User.class).sheet(" title 1").doWrite(user);
}
EasyExcel write in Excel
@Test
void testRead() throws Exception{
String fileName = path + "EasyExcel.xlsx";
// here You need to specify which to read class To read , Then read the first sheet The file stream closes automatically
EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
}
Realization function , operation Excel, The source code in Git On .
版权声明
本文为[Excellent face]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220532446872.html
边栏推荐
- 線性代數第二章-矩陣及其運算
- Example of reentrant lock thread waiting to wake up
- 8. Integer Decomposition
- 12. Monkeys climb mountains
- Create binary tree
- 数字图像处理基础(冈萨雷斯)一
- Common sense of thread pool
- The bottom implementation principle of thread - static agent mode
- 5.The Simple Problem
- Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
猜你喜欢
数字图像处理基础(冈萨雷斯)一
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
Pyemd installation and simple use
自动控制原理知识点整合归纳(韩敏版)
Latex quick start
Why does the subscript of the array start from 0 instead of 1?
CONDA virtual environment management (create, delete, clone, rename, export and import)
sklearn之 Gaussian Processes
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
随机推荐
Linear algebra Chapter 1 - determinant
On traversal of binary tree
卡尔曼滤波与惯性组合导航
12. Monkeys climb mountains
编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
container
Algèbre linéaire chapitre 1 - déterminants
Gaussian processes of sklearn
Fact final variable and final variable
List segmentation best practices
How does MySQL convert stored seconds into dates
9.Life, the Universe, and Everything
Anaconda
Pytorch learning record (XII): learning rate attenuation + regularization
Code neat way to learn
Example of ticket selling with reentrant lock
7.Domino piling
常用编程记录——parser = argparse.ArgumentParser()
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi