Skip to content

Commit 18cf427

Browse files
committed
[poi]: (3.0.0) updated the apache POI version to 5.2.5
1 parent 1117f75 commit 18cf427

File tree

5 files changed

+40
-31
lines changed

5 files changed

+40
-31
lines changed

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ This library is available in [Maven Central](https://mvnrepository.com/artifact/
2222
<dependency>
2323
<groupId>io.github.millij</groupId>
2424
<artifactId>poi-object-mapper</artifactId>
25-
<version>1.0.0</version>
25+
<version>3.0.0</version>
2626
</dependency>
2727
```
2828

2929
To install manually, please check the [releases](https://github.com/millij/poi-object-mapper/releases) page for available versions and change log.
3030

3131
#### Dependencies
3232

33-
The current implementation uses **POI version 4.0.1**.
33+
The current implementation uses **POI version 5.2.5**.
3434

3535

3636
## Usage
@@ -48,7 +48,7 @@ Consider the below sample spreadsheet, where data of employees is present.
4848

4949
##### Mapping Rows to a Java Bean
5050

51-
Create a java bean and map its properties to the columns using the `@SheetColumn` annotation. The `@SheetColumn` annotation can be declared on the `Field`, as well as its `Accessor Methods`. Pick any one of them to configure the mapped `Column` as per convenience.
51+
Create a java bean and map its properties to the columns using the `@SheetColumn` annotation. The `@SheetColumn` annotation can be declared on the `Field`, as well as its `Accessor Methods`. Pick any one of them to configure the mapped `Column` as per convenience.
5252

5353
```java
5454
@Sheet
@@ -68,34 +68,38 @@ public class Employee {
6868

6969
##### Reading Rows as Java Objects
7070

71-
Once a mapped Java Bean is ready, use a `Reader` to read the file rows as objects. Use `XlsReader` for `.xls` files and `XlsxReader` for `.xlsx` files.
71+
Once a mapped Java Bean is ready, use a `Reader` to read the file rows as objects.
72+
73+
Use `XlsReader` for `.xls` files and `XlsxReader` for `.xlsx` files.
7274

7375
Reading spreadsheet rows as objects ..
7476

7577
```java
7678
...
7779
final File xlsxFile = new File("<path_to_file>");
7880
final XlsReader reader = new XlsReader();
79-
List<Employee> employees = reader.read(Employee.class, xlsxFile);
81+
final List<Employee> employees = reader.read(Employee.class, xlsxFile);
8082
...
8183
```
8284

8385
##### Writing a collection of objects to file
8486

85-
*Currently writing to `.xlsx` files only is supported*
87+
Similar to `Reader`, the mapped Java Beans can be written to files.
88+
89+
Use `XlsWriter` for `.xls` files and `XlsxWriter` for `.xlsx` files.
8690

8791
```java
8892
...
8993
// Employees
90-
List<Employee> employees = new ArrayList<Employee>();
94+
final List<Employee> employees = new ArrayList<>();
9195
employees.add(new Employee("1", "foo", 12, "MALE", 1.68));
9296
employees.add(new Employee("2", "bar", null, "MALE", 1.68));
9397
employees.add(new Employee("3", "foo bar", null, null, null));
94-
98+
9599
// Writer
96-
SpreadsheetWriter writer = new SpreadsheetWriter("<output_file_path>");
100+
final SpreadsheetWriter writer = new XlsxWriter();
97101
writer.addSheet(Employee.class, employees);
98-
writer.write();
102+
writer.write("<output_file_path>");
99103
...
100104
```
101105

@@ -107,7 +111,7 @@ Reading spreadsheet rows as objects ..
107111

108112
The known issues are already listed under [Issues Section](https://github.com/millij/poi-object-mapper/issues).
109113

110-
Please add there your bugs findings, feature requests, enhancements etc.
114+
Please add there your bugs findings, feature requests, enhancements etc.
111115

112116

113117

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ dependencies {
2727
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.3'
2828

2929
// Apache Commons
30-
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
3130
implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4'
3231

3332
// Apache POI
34-
implementation group: 'org.apache.poi', name: 'poi', version: '4.1.2'
35-
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.2'
33+
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.5'
34+
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.2.5'
3635

3736

3837
// Test compile

src/main/java/io/github/millij/poi/ss/handler/AbstractSheetContentsHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package io.github.millij.poi.ss.handler;
22

3-
import io.github.millij.poi.util.Spreadsheet;
4-
53
import java.util.HashMap;
64
import java.util.Map;
5+
import java.util.Objects;
76

8-
import org.apache.commons.lang3.StringUtils;
97
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
108
import org.apache.poi.xssf.usermodel.XSSFComment;
119
import org.slf4j.Logger;
1210
import org.slf4j.LoggerFactory;
1311

12+
import io.github.millij.poi.util.Spreadsheet;
13+
1414

1515
abstract class AbstractSheetContentsHandler implements SheetContentsHandler {
1616

@@ -53,12 +53,12 @@ public void endRow(final int rowNum) {
5353
@Override
5454
public void cell(final String cellRef, final String cellVal, final XSSFComment comment) {
5555
// Sanity Checks
56-
if (StringUtils.isEmpty(cellRef)) {
56+
if (Objects.isNull(cellRef) || cellRef.isBlank()) {
5757
LOGGER.error("Row[#] {} : Cell reference is empty - {}", currentRow, cellRef);
5858
return;
5959
}
6060

61-
if (StringUtils.isEmpty(cellVal)) {
61+
if (Objects.isNull(cellVal) || cellVal.isBlank()) {
6262
LOGGER.warn("Row[#] {} - Cell[ref] formatted value is empty : {} - {}", currentRow, cellRef, cellVal);
6363
return;
6464
}

src/main/java/io/github/millij/poi/ss/reader/XlsReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private Object getCellValue(final HSSFCell cell) {
203203

204204
// Fetch value by CellType
205205
final Object cellVal;
206-
switch (cell.getCellTypeEnum()) {
206+
switch (cell.getCellType()) {
207207
case STRING:
208208
cellVal = cell.getStringCellValue();
209209
break;

src/main/java/io/github/millij/poi/util/Spreadsheet.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Map;
99
import java.util.Objects;
1010

11-
import org.apache.commons.lang3.StringUtils;
1211
import org.slf4j.Logger;
1312
import org.slf4j.LoggerFactory;
1413

@@ -61,10 +60,18 @@ public static String getCellColumnReference(final String cellRef) {
6160
*/
6261
public static String getSheetName(final Class<?> beanType) {
6362
final Sheet sheet = beanType.getAnnotation(Sheet.class);
64-
String sheetName = sheet != null ? sheet.value() : null;
63+
final String sheetName = Objects.isNull(sheet) ? null : sheet.value();
6564
return sheetName;
6665
}
6766

67+
public static String getSheetColumnName(final SheetColumn sheetColumn, final String defaultName) {
68+
// Name
69+
final String scValue = sheetColumn.value();
70+
final String colName = Objects.isNull(scValue) || scValue.isBlank() ? defaultName : scValue;
71+
72+
return colName;
73+
}
74+
6875
/**
6976
* Prepare {@link Column} def from {@link SheetColumn} annotation info.
7077
*
@@ -79,9 +86,8 @@ public static Column asColumn(final SheetColumn sheetCol, final String defaultNa
7986
return new Column(defaultName);
8087
}
8188

82-
// Name
83-
final String scVal = sheetCol.value();
84-
final String colName = Objects.isNull(scVal) || scVal.isBlank() ? defaultName : scVal;
89+
// Column Name
90+
final String colName = Spreadsheet.getSheetColumnName(sheetCol, defaultName);
8591

8692
// Prepare Column
8793
final Column column = new Column();
@@ -166,9 +172,9 @@ public static Map<String, String> asRowDataMap(final Object beanObj, final List<
166172
}
167173

168174
final String fieldName = f.getName();
175+
final SheetColumn sc = f.getAnnotation(SheetColumn.class);
169176

170-
final SheetColumn ec = f.getAnnotation(SheetColumn.class);
171-
final String header = StringUtils.isEmpty(ec.value()) ? fieldName : ec.value();
177+
final String header = Spreadsheet.getSheetColumnName(sc, fieldName);
172178
if (!colHeaders.contains(header)) {
173179
continue;
174180
}
@@ -183,9 +189,9 @@ public static Map<String, String> asRowDataMap(final Object beanObj, final List<
183189
}
184190

185191
final String fieldName = Beans.getFieldName(m);
192+
final SheetColumn sc = m.getAnnotation(SheetColumn.class);
186193

187-
final SheetColumn ec = m.getAnnotation(SheetColumn.class);
188-
final String header = StringUtils.isEmpty(ec.value()) ? fieldName : ec.value();
194+
final String header = Spreadsheet.getSheetColumnName(sc, fieldName);
189195
if (!colHeaders.contains(header)) {
190196
continue;
191197
}
@@ -226,7 +232,7 @@ public static <T> T rowAsBean(Class<T> beanClz, Map<String, Column> propColumnMa
226232
// Get the Header Cell Ref
227233
final String normalizedColName = Spreadsheet.normalize(propColName);
228234
final String propCellRef = headerCellRefsMap.get(normalizedColName);
229-
if (StringUtils.isEmpty(propCellRef)) {
235+
if (Objects.isNull(propCellRef) || propCellRef.isBlank()) {
230236
LOGGER.debug("{} :: No Cell Ref found [Prop - Col] : [{} - {}]", beanClz, propName, propColName);
231237
continue;
232238
}
@@ -272,7 +278,7 @@ private static boolean validateRowData(final Map<String, Object> rowDataMap,
272278
final String propCellRef = headerCellRefsMap.containsKey(propColName) //
273279
? headerCellRefsMap.get(propColName) //
274280
: headerCellRefsMap.get(normalizedColName);
275-
if (StringUtils.isEmpty(propCellRef)) {
281+
if (Objects.isNull(propCellRef) || propCellRef.isBlank()) {
276282
continue;
277283
}
278284

0 commit comments

Comments
 (0)