Skip to content

Commit ba2c6a7

Browse files
committed
add excel impl files, java version updates to 14
1 parent 9b2994e commit ba2c6a7

File tree

8 files changed

+505
-8
lines changed

8 files changed

+505
-8
lines changed

jitpack.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Workaround for any java version not supported by Jitpack.io yet
22
# https://github.com/jitpack/jitpack.io/issues/4260
3-
#before_install:
4-
# - wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
5-
# - source install-jdk.sh --feature 15
6-
# - jshell --version
7-
jdk:
8-
- openjdk11
3+
before_install:
4+
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
5+
- source install-jdk.sh --feature 14
6+
- jshell --version
7+
8+
# Laster may be supported by
9+
#jdk:
10+
# - openjdk14

pom.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
</scm>
4747

4848
<properties>
49-
<maven.compiler.source>11</maven.compiler.source>
50-
<maven.compiler.target>11</maven.compiler.target>
49+
<maven.compiler.source>14</maven.compiler.source>
50+
<maven.compiler.target>14</maven.compiler.target>
5151
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5252
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5353
</properties>
@@ -65,5 +65,22 @@
6565
<artifactId>table-wrapper-api</artifactId>
6666
<version>2020.12</version>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.apache.poi</groupId>
70+
<artifactId>poi</artifactId>
71+
<version>4.1.2</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.apache.poi</groupId>
75+
<artifactId>poi-ooxml</artifactId>
76+
<version>4.1.2</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.projectlombok</groupId>
80+
<artifactId>lombok</artifactId>
81+
<version>1.18.12</version>
82+
<scope>provided</scope>
83+
<optional>true</optional>
84+
</dependency>
6885
</dependencies>
6986
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Table Wrapper Excel Impl
3+
* Copyright (C) 2020 Vitalii Ananev <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.spacious_team.table_wrapper.excel;
20+
21+
import lombok.Getter;
22+
import lombok.RequiredArgsConstructor;
23+
import org.apache.poi.ss.usermodel.Row;
24+
import org.apache.poi.ss.usermodel.Sheet;
25+
import org.spacious_team.table_wrapper.api.ReportPage;
26+
import org.spacious_team.table_wrapper.api.TableCellAddress;
27+
import org.spacious_team.table_wrapper.api.TableRow;
28+
29+
import java.util.function.BiPredicate;
30+
31+
@RequiredArgsConstructor
32+
public class ExcelSheet implements ReportPage {
33+
34+
@Getter
35+
private final Sheet sheet;
36+
37+
@Override
38+
public TableCellAddress find(Object value, int startRow, int endRow, int startColumn, int endColumn,
39+
BiPredicate<String, Object> stringPredicate) {
40+
return ExcelTableHelper.find(sheet, value, startRow, endRow, startColumn, endColumn, stringPredicate);
41+
}
42+
43+
@Override
44+
public TableRow getRow(int i) {
45+
Row row = sheet.getRow(i);
46+
return (row == null) ? null : new ExcelTableRow(row);
47+
}
48+
49+
@Override
50+
public int getLastRowNum() {
51+
return sheet.getLastRowNum();
52+
}
53+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Table Wrapper Excel Impl
3+
* Copyright (C) 2020 Vitalii Ananev <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.spacious_team.table_wrapper.excel;
20+
21+
import lombok.ToString;
22+
import org.apache.poi.ss.usermodel.Cell;
23+
import org.spacious_team.table_wrapper.api.*;
24+
25+
import java.math.BigDecimal;
26+
import java.time.LocalDateTime;
27+
import java.util.Date;
28+
29+
@ToString(callSuper = true)
30+
public class ExcelTable extends AbstractTable {
31+
32+
ExcelTable(ReportPage reportPage,
33+
String tableName,
34+
TableCellRange tableRange,
35+
Class<? extends TableColumnDescription> headerDescription,
36+
int headersRowCount) {
37+
super(reportPage, tableName, tableRange, headerDescription, headersRowCount);
38+
}
39+
40+
@Override
41+
public Object getCellValue(TableRow row, TableColumnDescription columnDescription) {
42+
return ExcelTableHelper.getCellValue(getRawCell(row, columnDescription));
43+
}
44+
45+
@Override
46+
public int getIntCellValue(TableRow row, TableColumnDescription columnDescription) {
47+
return (int) getLongCellValue(row, columnDescription);
48+
}
49+
50+
@Override
51+
public long getLongCellValue(TableRow row, TableColumnDescription columnDescription) {
52+
return ExcelTableHelper.getLongCellValue(getRawCell(row, columnDescription));
53+
}
54+
55+
@Override
56+
public BigDecimal getCurrencyCellValue(TableRow row, TableColumnDescription columnDescription) {
57+
return ExcelTableHelper.getCurrencyCellValue(getRawCell(row, columnDescription));
58+
}
59+
60+
@Override
61+
public String getStringCellValue(TableRow row, TableColumnDescription columnDescription) {
62+
return ExcelTableHelper.getStringCellValue(getRawCell(row, columnDescription));
63+
}
64+
65+
public Date getDateCellValue(TableRow row, TableColumnDescription columnDescription) {
66+
return getRawCell(row, columnDescription).getDateCellValue();
67+
}
68+
69+
public LocalDateTime getLocalDateTimeCellValue(TableRow row, TableColumnDescription columnDescription) {
70+
return getRawCell(row, columnDescription).getLocalDateTimeCellValue();
71+
}
72+
73+
private Cell getRawCell(TableRow row, TableColumnDescription columnDescription) {
74+
return ((ExcelTableRow) row).getRow().getCell(columnIndices.get(columnDescription.getColumn()));
75+
}
76+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Table Wrapper Excel Impl
3+
* Copyright (C) 2020 Vitalii Ananev <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.spacious_team.table_wrapper.excel;
20+
21+
import lombok.Getter;
22+
import lombok.RequiredArgsConstructor;
23+
import org.apache.poi.ss.usermodel.Cell;
24+
import org.spacious_team.table_wrapper.api.TableCell;
25+
26+
@RequiredArgsConstructor
27+
public class ExcelTableCell implements TableCell {
28+
29+
@Getter
30+
private final Cell cell;
31+
32+
@Override
33+
public int getColumnIndex() {
34+
return cell.getColumnIndex();
35+
}
36+
37+
@Override
38+
public Object getValue() {
39+
return ExcelTableHelper.getCellValue(cell);
40+
}
41+
42+
@Override
43+
public String getStringCellValue() {
44+
return ExcelTableHelper.getStringCellValue(cell);
45+
}
46+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Table Wrapper Excel Impl
3+
* Copyright (C) 2020 Vitalii Ananev <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.spacious_team.table_wrapper.excel;
20+
21+
import org.spacious_team.table_wrapper.api.*;
22+
23+
public class ExcelTableFactory implements TableFactory {
24+
@Override
25+
public boolean canHandle(ReportPage reportPage) {
26+
return (reportPage instanceof ExcelSheet);
27+
}
28+
29+
@Override
30+
public Table create(ReportPage reportPage, String tableName, String tableFooterString,
31+
Class<? extends TableColumnDescription> headerDescription,
32+
int headersRowCount) {
33+
AbstractTable table = new ExcelTable(reportPage, tableName,
34+
reportPage.getTableCellRange(tableName, headersRowCount, tableFooterString),
35+
headerDescription,
36+
headersRowCount);
37+
table.setLastTableRowContainsTotalData(true);
38+
return table;
39+
}
40+
41+
@Override
42+
public Table create(ReportPage reportPage, String tableName,
43+
Class<? extends TableColumnDescription> headerDescription,
44+
int headersRowCount) {
45+
AbstractTable table = new ExcelTable(reportPage, tableName,
46+
reportPage.getTableCellRange(tableName, headersRowCount),
47+
headerDescription,
48+
headersRowCount);
49+
table.setLastTableRowContainsTotalData(false);
50+
return table;
51+
}
52+
53+
@Override
54+
public Table createOfNoName(ReportPage reportPage, String madeUpTableName, String firstLineText,
55+
Class<? extends TableColumnDescription> headerDescription,
56+
int headersRowCount) {
57+
AbstractTable table = new ExcelTable(reportPage, madeUpTableName,
58+
getNoNameTableRange(reportPage, firstLineText, headersRowCount),
59+
headerDescription,
60+
headersRowCount);
61+
table.setLastTableRowContainsTotalData(true);
62+
return table;
63+
}
64+
}

0 commit comments

Comments
 (0)