retheviper / ExcelWeaver

A simple library for manipulate excel file in java.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExcelWeaver

exceweaver

A simple library for manipulate excel file in java.

And there is Kotlin version of this library. Check this out.

TL;DR

*.xlsxjava.util.List

java.util.List*.xlsx

To build

./gradlew shadowJar

(And Jar will be found in build/libs)

To Use

Make definition of sheet

@Sheet(dataStartIndex = 2)
public class Contract { // Class name will be sheets name

    @Column(position = "B")
    private String name;

    @Column(position = "C")
    private String cellPhone;

    @Column(position = "D")
    private int postCode;
}

Make definition of book

// Create from array or list of SheetDef classes
BookDef bookDef = BookDef.of(Contract.class, Message.class);

// add more sheet
bookDef.addSheet(Salary.class);

Read file

List<Contract> list;
try (BookWorker worker = bookDef.openBook(OUTPUT_FILE_PATH)) {
    list = worker.read(Contract.class);
} catch (IOException e) {
    // ...
}

Write file

List<Contract> data = ...
try (BookWorker worker = bookDef.openBook(TEMPLATE_FILE_PATH, OUTPUT_FILE_PATH)) {
    worker.write(data);
} catch (IOException e) {
    // ...
}

About

A simple library for manipulate excel file in java.

License:MIT License


Languages

Language:Java 100.0%