Skip to content

Commit

Permalink
Update v2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rabanti-github committed Oct 26, 2024
1 parent 30f307c commit 35924e7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 30 deletions.
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## v2.4.2

---
Release Date: **26.10.2024**

- Fixed a bug regarding the determination of the first data cell in an empty worksheet. Bug fix provided by Martin Stránský for NanoXLSX (.NET)
- Updated Javadoc

## v2.4.1

---
Expand Down
2 changes: 1 addition & 1 deletion NanoXLSX4j.Demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>nanoxlsx4j-root</artifactId>
<groupId>ch.rabanti</groupId>
<version>2.4.1</version> <!-- Maintained in lib -->
<version>2.4.2</version> <!-- Maintained in lib -->
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion NanoXLSX4j.Lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ch.rabanti</groupId>
<artifactId>nanoxlsx4j</artifactId>
<version>2.4.1</version> <!-- Maintain also in demo and root project -->
<version>2.4.2</version> <!-- Maintain also in demo and root project -->
<packaging>jar</packaging>

<properties>
Expand Down
60 changes: 33 additions & 27 deletions NanoXLSX4j.Lib/src/main/java/ch/rabanti/nanoxlsx4j/Worksheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,9 @@ public Worksheet(String name, int id, Workbook reference) {
/**
* Adds an object to the next cell position. If the type of the value does not match with one of the supported data
* types, it will be cast to a String. A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @throws RangeException Thrown if the next cell is out of range (on row or column)
Expand All @@ -943,8 +944,9 @@ public void addNextCell(Object value) {
/**
* Adds an object to the next cell position. If the type of the value does not match with one of the supported data
* types, it will be cast to a String.A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @param style Style object to apply on this cell
Expand Down Expand Up @@ -1016,8 +1018,9 @@ else if (this.getCurrentCellDirection() == CellDirection.RowToRow) {
/**
* Adds an object to the defined cell address. If the type of the value does not match with one of the supported
* data types, it will be cast to a String. A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @param columnNumber Column number (zero based)
Expand All @@ -1032,8 +1035,9 @@ public void addCell(Object value, int columnNumber, int rowNumber) {
/**
* Adds an object to the defined cell address. If the type of the value does not match with one of the supported
* data types, it will be cast to a String. A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @param columnNumber Column number (zero based)
Expand All @@ -1050,8 +1054,9 @@ public void addCell(Object value, int columnNumber, int rowNumber, Style style)
/**
* Adds an object to the defined cell address. If the type of the value does not match with one of the supported
* data types, it will be cast to a String. A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @param address Cell address in the format A1 - XFD1048576
Expand All @@ -1067,8 +1072,9 @@ public void addCell(Object value, String address) {
/**
* Adds an object to the defined cell address. If the type of the value does not match with one of the supported
* data types, it will be cast to a String. A prepared object of the type Cell will not be cast but adjusted<br>
* Recognized are the following data types: Cell (prepared object), String, int, double, float, long, Date, boolean.
* All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param value Unspecified value to insert
* @param address Cell address in the format A1 - XFD1048576
Expand Down Expand Up @@ -1174,8 +1180,9 @@ public void addNextCellFormula(String formula, Style style) {
/**
* Adds a list of object values to a defined cell range. If the type of the particular value does not match with one
* of the supported data types, it will be cast to a String. A prepared object of the type Cell will not be cast but
* adjusted<br> Recognized are the following data types: Cell (prepared object), String, int, double, float, long,
* Date, boolean. All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param values List of unspecified objects to insert
* @param startAddress Start address
Expand All @@ -1190,8 +1197,9 @@ public void addCellRange(List<Object> values, Address startAddress, Address endA
/**
* Adds a list of object values to a defined cell range. If the type of the particular value does not match with one
* of the supported data types, it will be cast to a String. A prepared object of the type Cell will not be cast but
* adjusted<br> Recognized are the following data types: Cell (prepared object), String, int, double, float, long,
* Date, boolean. All other types will be cast into a String using the default toString() method
* Recognized are the following data types: Cell (prepared object), String, short, int, byte, double, float,
* boolean, long, BigDecimal, Date, Time, LocalTime. All other types will be cast into a String using the default
* toString() method
*
* @param values List of unspecified objects to insert
* @param startAddress Start address
Expand All @@ -1208,8 +1216,8 @@ public void addCellRange(List<Object> values, Address startAddress, Address endA
* Adds a list of object values to a defined cell range. If the type of the particular value does not match with one
* of the supported data types, it will be cast to a String. A prepared object of the type Cell will not be cast but
* adjusted<br> The data types in the passed list can be mixed. Recognized are the following data types: Cell
* (prepared object), String, int, double, float, long, Date, boolean. All other types will be cast into a String
* using the default toString() method
* (prepared object), String, short, int, byte, double, float, boolean, long, BigDecimal, Date, Time, LocalTime. All
* other types will be cast into a String using the default toString() method
*
* @param values List of unspecified objects to insert
* @param cellRange Cell range as string in the format like A1:D1 or X10:X22
Expand All @@ -1226,8 +1234,8 @@ public void addCellRange(List<Object> values, String cellRange) {
* Adds a list of object values to a defined cell range. If the type of the particular value does not match with one
* of the supported data types, it will be cast to a String. A prepared object of the type Cell will not be cast but
* adjusted<br> The data types in the passed list can be mixed. Recognized are the following data types: Cell
* (prepared object), String, int, double, float, long, Date, boolean. All other types will be cast into a String
* using the default toString() method
* * (prepared object), String, short, int, byte, double, float, boolean, long, BigDecimal, Date, Time, LocalTime. All
* * other types will be cast into a String using the default toString() method
*
* @param values List of unspecified objects to insert
* @param cellRange Cell range as string in the format like A1:D1 or X10:X22
Expand Down Expand Up @@ -1749,23 +1757,21 @@ else if (min) {
return cells.values().stream().max(Comparator.comparingInt(Cell::getColumnNumber)).get().getColumnNumber();
}
}
List<Cell> nonEmptyCells = cells.values().stream().filter(x -> x.getValue() != null).collect(Collectors.toList());
List<Cell> nonEmptyCells = cells.values().stream().filter(x -> x.getValue() != null && !x.getValue().toString().isEmpty()).collect(Collectors.toList());
if (nonEmptyCells.isEmpty()) {
return -1;
}
if (row && min) {
return nonEmptyCells.stream().filter(x -> x.getValue().toString() != "").min(Comparator.comparingInt(Cell::getRowNumber)).get().getRowNumber();
return nonEmptyCells.stream().min(Comparator.comparingInt(Cell::getRowNumber)).get().getRowNumber();
}
else if (row) {
return nonEmptyCells.stream().filter(x -> x.getValue().toString() != "").max(Comparator.comparingInt(Cell::getRowNumber)).get().getRowNumber();
return nonEmptyCells.stream().max(Comparator.comparingInt(Cell::getRowNumber)).get().getRowNumber();
}
else if (min) {
return nonEmptyCells.stream().filter(x -> x.getValue().toString() != "").min(Comparator.comparingInt(Cell::getColumnNumber)).get()
.getColumnNumber();
return nonEmptyCells.stream().min(Comparator.comparingInt(Cell::getColumnNumber)).get().getColumnNumber();
}
else {
return nonEmptyCells.stream().filter(x -> x.getValue().toString() != "").max(Comparator.comparingInt(Cell::getColumnNumber)).get()
.getColumnNumber();
return nonEmptyCells.stream().max(Comparator.comparingInt(Cell::getColumnNumber)).get().getColumnNumber();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,23 @@ void getFirstOrLastDataColumnNumberTest2() {
assertEquals(5, maxColumn);
}

@DisplayName("Test of the getFirstDataRowNumber and getLastDataRowNumber functions with an explicitly defined, cell with empty string besides other row definitions")
@ParameterizedTest(name = "Given empty cell address {0} should lead to -1 as first and last column")
@CsvSource(
{
"'F5'",
"'A1'"}
)
void getFirstOrLastDataRowNumberTest3(String emptyCellAddress)
{
Worksheet worksheet = new Worksheet();
worksheet.addHiddenRow(3);
worksheet.addHiddenRow(4);
worksheet.addCell("", emptyCellAddress);
int minRow = worksheet.getFirstDataRowNumber();
int maxRow = worksheet.getLastDataRowNumber();
assertEquals(-1, minRow);
assertEquals(-1, maxRow);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,23 @@ void getFirstOrLastDataColumnNumberTest2() {
assertEquals(4, minRow);
assertEquals(4, maxRow);
}

@DisplayName("Test of the getFirstDataColumnNumber and getLastDataColumnNumber functions with an explicitly defined, empty cell with empty string besides other column definitions")
@ParameterizedTest(name = "Given empty cell address {0} should lead to -1 as first and last row")
@CsvSource(
{
"'F5'",
"'A1'"}
)
public void getFirstOrLastDataColumnNumberTest3(String emptyCellAddress)
{
Worksheet worksheet = new Worksheet();
worksheet.addHiddenColumn(3);
worksheet.addHiddenColumn(4);
worksheet.addCell("", emptyCellAddress);
int minColumn = worksheet.getFirstDataColumnNumber();
int maxColumn = worksheet.getLastDataColumnNumber();
assertEquals(-1, minColumn);
assertEquals(-1, maxColumn);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>ch.rabanti</groupId>
<artifactId>nanoxlsx4j-root</artifactId>
<packaging>pom</packaging>
<version>2.4.1</version>
<version>2.4.2</version>
<modules>
<module>NanoXLSX4j.Lib</module>
<!-- Do not add this to build -->
Expand Down

0 comments on commit 35924e7

Please sign in to comment.