Skip to content

Commit

Permalink
Merge pull request #1 from spacious-team/develop
Browse files Browse the repository at this point in the history
Релиз 2023.1
  • Loading branch information
vananiev authored May 31, 2023
2 parents 82a2f24 + 892a108 commit 4a5c1bd
Show file tree
Hide file tree
Showing 15 changed files with 943 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
target/
#.mvn
!.mvn/wrapper/maven-wrapper.properties
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
!.idea/runConfigurations
!.idea/codeStyles
!.idea/copyright
!.idea/inspectionProfiles

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/GNU_AGPLv3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions .idea/inspectionProfiles/Inspections.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
![java-version](https://img.shields.io/badge/Java-11-brightgreen?style=flat-square)
[![spring-boot-version](https://img.shields.io/badge/spring--boot-2.7+-brightgreen?style=flat-square)](https://github.com/spring-projects/spring-boot/releases)
[![jitpack-last-release](https://jitpack.io/v/spacious-team/table-wrapper-spring-boot-starter.svg?style=flat-square)](
https://jitpack.io/#spacious-team/table-wrapper-api)

### Назначение
Позволяет работать с табличным представлением данных в форматах Excel, Xml и Csv через единый интерфейс
[Table Wrapper API](https://github.com/spacious-team/table-wrapper-api).

Совместим с проектами Spring Boot 2.7 и выше.

Spring Boot Starter настраивает реализации фабрик `ExcelTableFactory`, `XmlTableFactory`, `CsvTableFactory`
и подключает необходимые зависимости
1. [table-wrapper-excel-impl](https://github.com/spacious-team/table-wrapper-excel-impl) для работы с excel файлами
```xml
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>table-wrapper-excel-impl</artifactId>
</dependency>
```
2. [table-wrapper-xml-impl](https://github.com/spacious-team/table-wrapper-xml-impl) для работы с xml файлами
```xml
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>table-wrapper-xml-impl</artifactId>
</dependency>
```
3. [table-wrapper-csv-impl](https://github.com/spacious-team/table-wrapper-csv-impl) для работы с csv (tsv) файлами
```xml
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>table-wrapper-csv-impl</artifactId>
</dependency>
```

### Подключение стартера к проекту
Необходимо подключить репозиторий open source библиотек github
[jitpack](https://jitpack.io/#spacious-team/table-wrapper-spring-boot-starter), например для Apache Maven проекта
```xml
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```
Далее добавить зависимость
```xml
<dependency>
<groupId>com.github.spacious-team</groupId>
<artifactId>table-wrapper-spring-boot-starter</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
```

В качестве версии можно использовать:
- версию [релиза](https://github.com/spacious-team/table-wrapper-spring-boot-starter/releases) на github;
- паттерн `<branch>-SNAPSHOT` для сборки зависимости с последнего коммита выбранной ветки;
- короткий десяти значный номер коммита для сборки зависимости с указанного коммита.

### Пример использования
Определяются колонки таблицы вне зависимости от формата файла (excel, xml, csv и др.):
```java
@lombok.Getter
@lombok.RequiredArgsConstructor
enum TableHeader implements TableHeaderColumn {
PRODUCT(PatternTableColumn.of("Товар")),
PRICE(PatternTableColumn.of("Цена"));

private final TableColumn column;
}
```
Извлекаем данные в описанном формате, например, из Excel файла через Stream API
```java
Workbook book = new XSSFWorkbook(xlsFileinputStream); // открываем Excel файл
ReportPage reportPage = new ExcelSheet(book.getSheetAt(0)); // используем 1-ый лист Excel файла для поиска таблицы

// Регистронезависимо найдет ячейку с текстом "Таблица 1",
// парсит следующую за ней строку как заголовок таблицы,
// оставшиеся строки парсятся как данные до пустой строки или конца файла
Table table = reportPage.create("таблица 1", TableHeader.class); // метод использует бин ExcelTableFactory для создания таблицы

// Извлекаем и обрабатываем строки таблицы
table.stream()
.forEach(row -> {
String product = row.getStringCellValue(TableHeader.PRODUCT);
BigDecimal price = getBigDecimalCellValue(TableHeader.PRICE);
});
```
8 changes: 8 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Workaround for any java version not supported by Jitpack.io yet
# https://github.com/jitpack/jitpack.io/issues/4260
#before_install:
# - wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
# - source install-jdk.sh --feature 15
# - jshell --version
jdk:
- openjdk11
Loading

0 comments on commit 4a5c1bd

Please sign in to comment.