Excel IO

Excel读取写入器

License

License

GroupId

GroupId

com.github.developframework
ArtifactId

ArtifactId

excel-io
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Excel IO
Excel读取写入器
Project URL

Project URL

https://github.com/developframework/excel-io
Source Code Management

Source Code Management

https://github.com/developframework/excel-io

Download excel-io

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.developframework/excel-io/ -->
<dependency>
    <groupId>com.github.developframework</groupId>
    <artifactId>excel-io</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.developframework/excel-io/
implementation 'com.github.developframework:excel-io:1.0'
// https://jarcasting.com/artifacts/com.github.developframework/excel-io/
implementation ("com.github.developframework:excel-io:1.0")
'com.github.developframework:excel-io:jar:1.0'
<dependency org="com.github.developframework" name="excel-io" rev="1.0">
  <artifact name="excel-io" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.developframework', module='excel-io', version='1.0')
)
libraryDependencies += "com.github.developframework" % "excel-io" % "1.0"
[com.github.developframework/excel-io "1.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar 1.18.12
org.apache.poi : poi jar 4.1.0
org.apache.poi : poi-ooxml jar 4.1.0
org.apache.commons : commons-lang3 jar 3.9
com.github.developframework : expression jar 1.5.0
com.github.developframework : develop-toolkit-base jar 1.0.3

Project Modules

There are no modules declared in this project.

excel-io

封装poi对Office Excel的输入输出工具,简化简单的导入和导出Excel数据的操作。(暂不支持合并单元格)

<dependency>
    <groupId>com.github.developframework</groupId>
    <artifactId>excel-io</artifactId>
</dependency>

教程

假设存在实体Customer包装数据

@Data
public class Customer {

    private String name;

    private LocalDate buyDate;

    private String[] tickets;

    private int cost;
}

ExcelIO

使用ExcelIO得到输入输出处理器

ExcelWriter

ExcelIO
    .writer(ExcelType.XLSX)
	.load(customers, tableDefinition)
    .write(outputStream);

ExcelReader

List<Customer> customers = ExcelIO
    .reader(ExcelType.XLSX, inputStream)
    .read(Customer.class, tableDefinition);

TableDefinition

该接口是表格的定义类,一个定义类代表了一个数据表

通过该接口可以设置表格的表头信息和表格的左上角单元格位置(工作表、行、列)。

可实现方法 说明 默认值
hasTitle() 表格顶部是否含有标题 false
title() 标题文本 null
hasColumnHeader() 是否有列说明 true
sheetName() 工作表名称 null
tableLocation() 表格位置(起始行,起始列) null
columnDefinitions(Workbook, ColumnDefinitionBuilder) 列定义 未实现
sheetExtraHandler() 工作表其它扩展处理 null

ColumnDefinition

该抽象类是表格的列定义类,一个定义类代表了表中的某一列,指代了一个字段

内置有如下实现类:

  • StringColumnDefinition

    文本列,默认单元格格式为加边框,文字居中,单元格类型为STRING

  • FormulaColumnDefinition

    公式列,默认单元格格式为加边框,文字居中,单元格类型为FORMULA

  • NumericColumnDefinition

    数值列,默认单元格格式为加边框,文字居中,单元格类型为NUMERIC

  • BlankColumnDefintion

    空白列,默认单元格格式为加边框,文字居中,单元格类型为BLANK

  • MultipleLinesColumnDefinition

    多行文本列,默认单元格格式为加边框,文字居中,单元格类型为STRING

写出数据到Excel

使用excel-io导入customer数据

List<Customer> customers = new LinkedList<>();
// 准备数据略
ExcelIO
        .writer(ExcelType.XLSX)
        .load(customers, (workbook, builder) -> builder.columnDefinitions(
                builder.string("name", "姓名"),
                builder.string("buyDate", "购买日期"),
                builder.multipleLines("tickets", "所购门票"),
                builder.numeric("cost", "花费").format("¥0.00")
        ))
        .write(outputStream);

从Excel读取数据

使用excel-io导出customer数据

List<Customer> customers = ExcelIO
        .reader(inputStream)
        .read(Customer.class, (workbook, builder) -> builder.columnDefinitions(
                builder.string("name", "姓名"),
                builder.string("buyDate", "购买日期"),
                builder.multipleLines("tickets", "所购门票"),
                builder.numeric("cost", "花费").format("¥0.00")
        ));

Versions

Version
1.0
0.1