diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ed9eb71..3214411e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## v4.0.1
+## v4.1.0
The following Changelog lists the changes. Please refer to the [documentation](docs/README.md) for configuration needs and understanding the concept changes.
@@ -14,6 +14,7 @@ The **need for configuration updates** is **marked bold**.
### Added
- Added Material Number in material details view ([#1005](https://github.com/eclipse-tractusx/puris/pull/1005))
+- added formula support for excel imports ([#1020](https://github.com/eclipse-tractusx/puris/pull/1020))
### Changed
diff --git a/backend/pom.xml b/backend/pom.xml
index a01ab6a8..0a872a9e 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -33,7 +33,7 @@
org.eclipse.tractusx.puris
puris-backend
- 4.0.1
+ 4.1.0
puris-backend
PURIS Backend
diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/file/logic/service/ExcelService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/file/logic/service/ExcelService.java
index a0a5b39f..6567ffe9 100644
--- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/file/logic/service/ExcelService.java
+++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/file/logic/service/ExcelService.java
@@ -134,6 +134,8 @@ public class ExcelService {
public DataImportResult readExcelFile(InputStream is) throws IOException {
Workbook workbook = WorkbookFactory.create(is);
Sheet sheet = workbook.getSheetAt(0);
+ FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
+ evaluator.evaluateAll();
var result = extractAndSaveData(sheet);
workbook.close();
return result;
@@ -688,9 +690,23 @@ private List extractHeader(Sheet sheet) {
}
private String getStringCellValue(Cell cell) {
- return cell == null || cell.getCellType() == CellType.BLANK ? null : cell.getCellType() == CellType.STRING
- ? cell.getStringCellValue().trim()
- : String.valueOf(cell.getNumericCellValue()).trim();
+ if (cell == null || cell.getCellType() == CellType.BLANK) {
+ return null;
+ }
+ CellType type = cell.getCellType();
+ if (type == CellType.FORMULA) {
+ type = cell.getCachedFormulaResultType();
+ }
+ switch (type) {
+ case STRING:
+ return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
+ case NUMERIC:
+ return String.valueOf(cell.getNumericCellValue()).trim();
+ case BOOLEAN:
+ return String.valueOf(cell.getBooleanCellValue());
+ default:
+ return null;
+ }
}
private Date getDateCellValue(Cell cell) {
diff --git a/backend/src/test/java/org/eclipse/tractusx/puris/backend/file/logic/services/ExcelServiceTest.java b/backend/src/test/java/org/eclipse/tractusx/puris/backend/file/logic/services/ExcelServiceTest.java
index fd84a528..44ab1117 100644
--- a/backend/src/test/java/org/eclipse/tractusx/puris/backend/file/logic/services/ExcelServiceTest.java
+++ b/backend/src/test/java/org/eclipse/tractusx/puris/backend/file/logic/services/ExcelServiceTest.java
@@ -81,7 +81,9 @@ public class ExcelServiceTest {
private static final Material testMaterial;
private static final Partner testPartner;
- private static final Date testDate = Date.from(Instant.parse("2025-01-15T10:00:00Z"));
+ private static final String todaysDateFromFormula = "=TODAY()";
+ private static final String tomorrowsDateFromFormula = "=TODAY()+1";
+ private static final Date todaysDateFromParsing = Date.from(Instant.now());
private static final String OWN_BPNS = "BPNS1234567890AB";
private static final String OWN_BPNA = "BPNA1234567890AB";
@@ -135,27 +137,27 @@ public class ExcelServiceTest {
SAMPLE_DEMAND_ROW = List.of(
testMaterial.getOwnMaterialNumber(), testPartner.getBpnl(), 100.0, "unit:piece",
OWN_BPNS, PARTNER_BPNS, "0001",
- testDate, testDate
+ todaysDateFromFormula, todaysDateFromParsing
);
SAMPLE_PRODUCTION_ROW = List.of(
testMaterial.getOwnMaterialNumber(), testPartner.getBpnl(), 100.0, "unit:piece",
- OWN_BPNS, testDate, "ORDER-001",
- "POS-001", "SUPPLY-001", testDate
+ OWN_BPNS, todaysDateFromFormula, "ORDER-001",
+ "POS-001", "SUPPLY-001", todaysDateFromParsing
);
SAMPLE_DELIVERY_ROW = List.of(
testMaterial.getOwnMaterialNumber(), testPartner.getBpnl(), 100.0, "unit:piece",
OWN_BPNS, OWN_BPNA, PARTNER_BPNS, PARTNER_BPNA,
- "estimated-departure", testDate, "estimated-arrival", testDate,
+ "estimated-departure", todaysDateFromFormula, "estimated-arrival", tomorrowsDateFromFormula,
"TRACK-001", "EXW", "ORDER-001", "POS-001",
- "SUPPLY-001", testDate
+ "SUPPLY-001", todaysDateFromParsing
);
SAMPLE_STOCK_ROW = List.of(
testMaterial.getOwnMaterialNumber(), testPartner.getBpnl(), 100.0, "unit:piece",
OWN_BPNS, OWN_BPNA, "ORDER-001", "POS-001",
- "SUPPLY-001", false, testDate, "INBOUND"
+ "SUPPLY-001", false, todaysDateFromParsing, "INBOUND"
);
}
@@ -508,7 +510,7 @@ private ByteArrayInputStream createDemandExcelFileWithInvalidUnit() throws IOExc
List