This is an automated email from the ASF dual-hosted git repository.

pvillard31 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 5f38672e738 NIFI-16429 Allowed for evaluating formulas for Header Row 
in ExcelReader when using the "Use Starting Row" strategy. (#11820)
5f38672e738 is described below

commit 5f38672e738068d58252f4a233164010ccc7f986
Author: dan-s1 <[email protected]>
AuthorDate: Wed Oct 21 07:25:00 2026 -0400

    NIFI-16429 Allowed for evaluating formulas for Header Row in ExcelReader 
when using the "Use Starting Row" strategy. (#11820)
---
 .../excel/ExcelStartingRowSchemaInference.java     |  1 +
 .../excel/TestExcelStartingRowSchemaInference.java | 35 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelStartingRowSchemaInference.java
 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelStartingRowSchemaInference.java
index 2170696345e..f387f50c250 100644
--- 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelStartingRowSchemaInference.java
+++ 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelStartingRowSchemaInference.java
@@ -63,6 +63,7 @@ public class ExcelStartingRowSchemaInference implements 
SchemaInferenceEngine<Ro
         this.firstRow = firstRow;
         this.cellFieldTypeReader = new 
StandardCellFieldTypeReader(timeValueInference);
         this.dataFormatter = new DataFormatter();
+        this.dataFormatter.setUseCachedValuesForFormulaCells(true);
         this.ignoreCellsBeyondHeader = ignoreCellsBeyondHeader;
         this.logger = logger;
     }
diff --git 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelStartingRowSchemaInference.java
 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelStartingRowSchemaInference.java
index 8d6bb8ac5a8..8ea17a6c157 100644
--- 
a/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelStartingRowSchemaInference.java
+++ 
b/nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/test/java/org/apache/nifi/excel/TestExcelStartingRowSchemaInference.java
@@ -31,6 +31,8 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.CreationHelper;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.jupiter.api.AfterAll;
@@ -348,6 +350,39 @@ public class TestExcelStartingRowSchemaInference {
         }
     }
 
+    @ParameterizedTest
+    @EnumSource(RowEvaluationStrategy.class)
+    void testWithFormulaInHeader(RowEvaluationStrategy rowEvaluationStrategy) 
throws Exception {
+        try (Workbook workbook = new XSSFWorkbook();
+             ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) 
{
+
+            final Sheet firstSheet = workbook.createSheet("First Sheet");
+            final Row headerRow = firstSheet.createRow(0);
+            headerRow.createCell(0).setCellValue("test_col1");
+            headerRow.createCell(1).setCellFormula(
+                    "\"value_in_\"&'Second Sheet'!B1");
+            headerRow.createCell(2).setCellValue("test_col3");
+
+            final Sheet secondSheet = workbook.createSheet("Second Sheet");
+            final Row firstRow = secondSheet.createRow(0);
+            firstRow.createCell(0).setCellValue("Currency");
+            firstRow.createCell(1).setCellValue("USD");
+
+            // Calculate the formula and save its cached result in the 
workbook.
+            workbook.getCreationHelper()
+                    .createFormulaEvaluator()
+                    .evaluateAll();
+
+            workbook.write(outputStream);
+            final byte[] output = outputStream.toByteArray();
+            final InputStream inputStream = new ByteArrayInputStream(output);
+            final InferSchemaAccessStrategy<?> inferSchemaAccessStrategy = 
getInferSchemaAccessStrategy(rowEvaluationStrategy);
+
+            final RecordSchema schema = 
inferSchemaAccessStrategy.getSchema(null, inputStream, null);
+            assertEquals(List.of("test_col1", "value_in_USD", "test_col3"), 
schema.getFieldNames());
+        }
+    }
+
     private InferSchemaAccessStrategy<?> 
getInferSchemaAccessStrategy(RowEvaluationStrategy rowEvaluationStrategy) {
         return getInferSchemaAccessStrategy(rowEvaluationStrategy, false);
     }

Reply via email to