A DbSetup extension to import data from Microsoft Excel files.
- Java 11+
testImplementation 'com.sciencesakura:dbsetup-spreadsheet:2.0.1'
testImplementation 'com.sciencesakura:dbsetup-spreadsheet-kt:2.0.1'
<dependency>
<groupId>com.sciencesakura</groupId>
<artifactId>dbsetup-spreadsheet</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sciencesakura</groupId>
<artifactId>dbsetup-spreadsheet-kt</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
When there are tables below:
create table country (
id integer not null,
code char(3) not null,
name varchar(256) not null,
primary key (id),
unique (code)
);
create table customer (
id integer not null,
name varchar(256) not null,
country integer not null,
primary key (id),
foreign key (country) references country (id)
);
Create An Excel file with one worksheet per table, and name those worksheets the same as the tables. If there is a dependency between the tables, put the worksheet of the dependent table early.
country
sheet:
id | code | name |
---|---|---|
1 | GBR | United Kingdom |
2 | HKG | Hong Kong |
3 | JPN | Japan |
customer
sheet:
id | name | country |
---|---|---|
1 | Eriol | 1 |
2 | Sakura | 3 |
3 | Xiaolang | 2 |
Put the prepared Excel file on the classpath, and write code like the below:
Java:
import static com.sciencesakura.dbsetup.spreadsheet.Import.excel;
var operation = excel("testdata.xlsx").build();
var dbSetup = new DbSetup(destination, operation);
dbSetup.launch();
Kotlin:
import com.sciencesakura.dbsetup.spreadsheet.excel
dbSetup(destination) {
excel("testdata.xlsx")
}.launch()
See API reference for details.
MIT License
Copyright (c) 2019 sciencesakura