-
Notifications
You must be signed in to change notification settings - Fork 325
Excel CSV import
清沐 edited this page Feb 18, 2020
·
1 revision
Import is divided into general import and sax import. The difference between them is that Sax import pays more attention to memory, uses less memory, and the Sax import function is enhanced. It is recommended to use Sax import (readable formula value)。
URL htmlToExcelEampleURL = this.getClass().getResource("/templates/read_example.xlsx");
Path path = Paths.get(htmlToExcelEampleURL.toURI());
// Mode 1: after reading all
List<ArtCrowd> result = DefaultExcelReader.of(ArtCrowd.class)
.sheet(0) // 0 represents the first sheet. If it is 0, the operation can be omitted or sheet ("name") can read it
.rowFilter(row -> row.getRowNum() > 0) // If no filtering is needed, the operation can be omitted. 0 represents the first line
.beanFilter(ArtCrowd::isDance) // Bean filtering
.read(path.toFile());// Can receive InputStream
// Mode 2: read one line and process one line, and you can decide the termination conditions at your own discretion
// Readthen has two rewriting interfaces. Returning a Boolean interface allows the reading to be terminated directly when returning false
DefaultExcelReader.of(ArtCrowd.class)
.sheet(0)
.rowFilter(row -> row.getRowNum() > 0)
.beanFilter(ArtCrowd::isDance)
.readThen(path.toFile() ,artCrowd -> {System.out.println(artCrowd.getName);});
public class ArtCrowd {
// Index represents column index, starting from 0
// Annotation free import is supported, i.e. it does not need to specify the column corresponding to the field @Excelcolumn, and will be imported in the default order of all fields
// Can be read according to the specified title
@ExcelColumn(index = 0)
private String name;
@ExcelColumn(index = 1)
private String age;
@ExcelColumn(index = 2,format="yyyy-MM-dd")
private Date birthday;
}
The import interface of CSV file is the same as the import interface of Excel, only the import file is different, the program will automatically distinguish
To import as map, set the import class to
SaxExcelReader.Of(Map.class)
, the result isList<Map>
, the actual type of map is LinkedHashMap, the key value isCell
, and the value value is the content value of string type
URL htmlToExcelEampleURL = this.getClass().getResource("/templates/read_example.xlsx");
Path path = Paths.get(htmlToExcelEampleURL.toURI());
// Mode 1: after reading all data, Sax mode, avoiding OOM, recommended to use a large amount of data
List<ArtCrowd> result = SaxExcelReader.of(ArtCrowd.class)
.sheet(0) // 0 represents the first sheet. If it is 0, the operation can be omitted or sheet ("name") can be read. CSV file is invalid
.rowFilter(row -> row.getRowNum() > 0) // If no filtering is needed, the operation can be omitted. 0 represents the first line
.charset("GBK") // Currently, only. CSV file is valid. Set the code of current file
.beanFilter(ArtCrowd::isDance) // Bean filtering
.read(path.toFile());// Can receive InputStream
// Mode 2: read one line and process one line. You can decide the termination conditions by yourself. Sax mode can avoid OOM. It is recommended to use a large amount of data
// Readthen has two rewriting interfaces. Returning a Boolean interface allows the reading to be terminated directly when returning false
SaxExcelReader.of(ArtCrowd.class)
.sheet(0)
.rowFilter(row -> row.getRowNum() > 0)
.charset("GBK")
.beanFilter(ArtCrowd::isDance)
.readThen(path.toFile() ,artCrowd -> {System.out.println(artCrowd.getName);});
public class ArtCrowd {
// Index represents column index, starting from 0
// Annotation free import is supported, i.e. it does not need to specify the column corresponding to the field @Excelcolumn, and will be imported in the default order of all fields
// Can be read according to the specified title
@ExcelColumn(index = 0)
private String name;
@ExcelColumn(index = 1)
private String age;
@ExcelColumn(index = 2,format="yyyy-MM-dd")
private Date birthday;
}
For details of corresponding notes, please refer to notes
For operation API, see API
-
Overview
概述 -
FAQ
常见问题 -
Dependency adding
依赖添加 -
Excel/Csv import
Excel/Csv导入 - 一对多导入
-
Excel default export
默认导出 -
Excel streaming export
流式导出 -
Dynamic export
动态导出 -
Excel template build
模板构建 -
CSV export
csv导出 -
Multiple sheet import
多sheet导入 -
Multiple sheet export
多sheet导出 - 聚合列&聚合导出
-
Custom style
自定义样式 -
Multilevel header
多级表头 -
Wrap within cell
单元格内换行 -
Image export
图片导出 -
Image import
图片导入 -
Hyperlink
链接 - 读取链接
-
Template row height setting
模板行高度设置 -
Drop-down-list
下拉列表 -
Custom convert
写入自定义转化 -
Formula usage
公式使用 -
Template cell setting
单元格设置 -
Header freeze
区域冻结 - 提示
-
Style support
样式支持 - 添加水印
- 按列读取
- 单元格斜线绘制
- 设置批注
- 版本日志