diff --git a/jxls-poi/src/test/java/org/jxls/TestWorkbook.java b/jxls-poi/src/test/java/org/jxls/TestWorkbook.java
index ac9ab91f..2082a719 100644
--- a/jxls-poi/src/test/java/org/jxls/TestWorkbook.java
+++ b/jxls-poi/src/test/java/org/jxls/TestWorkbook.java
@@ -51,10 +51,11 @@ public void selectSheet(int index) {
* @return String
*/
public String getCellValueAsString(int row, int column) {
- if (sheet.getRow(row - 1).getCell(column - 1) == null) {
+ try {
+ return sheet.getRow(row - 1).getCell(column - 1).getStringCellValue();
+ } catch (NullPointerException e) {
return null;
}
- return sheet.getRow(row - 1).getCell(column - 1).getStringCellValue();
}
/**
@@ -64,7 +65,11 @@ public String getCellValueAsString(int row, int column) {
* @return RichTextString.toString()
*/
public String getCellValueAsRichString(int row, int column) {
- return sheet.getRow(row - 1).getCell(column - 1).getRichStringCellValue().toString();
+ try {
+ return sheet.getRow(row - 1).getCell(column - 1).getRichStringCellValue().toString();
+ } catch (NullPointerException e) {
+ return null;
+ }
}
/**
@@ -84,7 +89,11 @@ public int getCellValueAsRichStringNumFormattingRuns(int row, int column) {
* @return String
*/
public String getFormulaString(int row, int column) {
- return sheet.getRow(row - 1).getCell(column - 1).getCellFormula();
+ try {
+ return sheet.getRow(row - 1).getCell(column - 1).getCellFormula();
+ } catch (NullPointerException e) {
+ return null;
+ }
}
/**
@@ -94,7 +103,11 @@ public String getFormulaString(int row, int column) {
* @return Double
*/
public Double getCellValueAsDouble(int row, int column) {
- return sheet.getRow(row - 1).getCell(column - 1).getNumericCellValue();
+ try {
+ return sheet.getRow(row - 1).getCell(column - 1).getNumericCellValue();
+ } catch (NullPointerException e) {
+ return null;
+ }
}
/**
@@ -104,7 +117,11 @@ public Double getCellValueAsDouble(int row, int column) {
* @return LocalDateTime
*/
public LocalDateTime getCellValueAsLocalDateTime(int row, int column) {
- return sheet.getRow(row - 1).getCell(column - 1).getLocalDateTimeCellValue();
+ try {
+ return sheet.getRow(row - 1).getCell(column - 1).getLocalDateTimeCellValue();
+ } catch (NullPointerException e) {
+ return null;
+ }
}
/**
diff --git a/jxls-poi/src/test/resources/org/jxls/templatebasedtests/GroupSumTest_filterCondition.xlsx b/jxls-poi/src/test/resources/org/jxls/templatebasedtests/GroupSumTest_filterCondition.xlsx
index d7d67ad1..9f7da4df 100644
Binary files a/jxls-poi/src/test/resources/org/jxls/templatebasedtests/GroupSumTest_filterCondition.xlsx and b/jxls-poi/src/test/resources/org/jxls/templatebasedtests/GroupSumTest_filterCondition.xlsx differ
diff --git a/jxls-poi/src/test/resources/org/jxls/templatebasedtests/OrderByTest.xlsx b/jxls-poi/src/test/resources/org/jxls/templatebasedtests/OrderByTest.xlsx
index 95265299..b7345047 100644
Binary files a/jxls-poi/src/test/resources/org/jxls/templatebasedtests/OrderByTest.xlsx and b/jxls-poi/src/test/resources/org/jxls/templatebasedtests/OrderByTest.xlsx differ
diff --git a/jxls-site/src/site/markdown/changes.md b/jxls-site/src/site/markdown/changes.md
index 6bd6b7a1..693657f4 100644
--- a/jxls-site/src/site/markdown/changes.md
+++ b/jxls-site/src/site/markdown/changes.md
@@ -6,6 +6,7 @@ v2.12.0
* [#164 Update commons-compress](https://github.com/jxlsteam/jxls/issues/164)
* [#147 Row height bugfix](https://github.com/jxlsteam/jxls/issues/147), contribution by [jools-uk](https://github.com/jools-uk)
* [#153 Issue in Excel Output while using SXSSF Transformer](https://github.com/jxlsteam/jxls/issues/153)
+* [#148 Inconsistent use of var prefix in EachCommand](https://github.com/jxlsteam/jxls/issues/148)
You should write var+"." before each property name in orderBy and groupBy.
* [#129 GroupSum with condition](https://github.com/jxlsteam/jxls/issues/129) see example: GroupSumTest
* [#73 Exceptions not propagated in EachCommand](https://github.com/jxlsteam/jxls/issues/73)
diff --git a/jxls-site/src/site/markdown/reference/each_command.md b/jxls-site/src/site/markdown/reference/each_command.md
index 90270890..ff82d2e2 100644
--- a/jxls-site/src/site/markdown/reference/each_command.md
+++ b/jxls-site/src/site/markdown/reference/each_command.md
@@ -22,11 +22,11 @@ Command Attributes
* `select` is an expression selector to filter out collection items during the iteration
-* `groupBy` is a property to do the grouping
+* `groupBy` is a property to do the grouping (prepend the var name + ".")
* `groupOrder` indicates ordering for groups ('desc' or 'asc')
-* `orderBy` contains the names separated with comma and each with an optional postfix " ASC" (default) or " DESC" for the sort order
+* `orderBy` contains the property names separated with comma and each with an optional postfix " ASC" (default) or " DESC" for the sort order. You should prepend the var name + "." before each property name.
* `multisheet` is a name of a context variable containing a list of sheet names to output the collection
@@ -95,15 +95,16 @@ With Java API you do this like
Grouping the data
------------------
*Each-Command* supports grouping via its `groupBy` property. The `groupOrder` property sets the ordering and can be `desc` or `asc`.
-If you write `groupBy` without `groupOrder` no sorting will be done.
+If you write `groupBy` without `groupOrder` no sorting will be done. Normally one defines `groupBy` and `groupOrder`.
In the excel markup it can look like this
- jx:each(items="employees" var="myGroup" groupBy="name" groupOrder="asc" lastCell="D6")
+ jx:each(items="employees" var="myGroup" groupBy="myGroup.name" groupOrder="asc" lastCell="D6")
In this example each group can be referred using _myGroup_ variable which will be accessible in the context.
+For consistent use you should write the var name + "." before the groupBy property name.
-The current group item can be referred using `myGroup.item`. So to refer to employee name use
+The current group item can be referred using `myGroup.item`. So to refer to employee name use
${myGroup.item.name}
diff --git a/jxls/src/main/java/org/jxls/command/EachCommand.java b/jxls/src/main/java/org/jxls/command/EachCommand.java
index c710e263..df068a26 100644
--- a/jxls/src/main/java/org/jxls/command/EachCommand.java
+++ b/jxls/src/main/java/org/jxls/command/EachCommand.java
@@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
import org.jxls.area.Area;
import org.jxls.common.CellRef;
@@ -23,10 +24,10 @@
*