Read formula cells by evaluating, not just the cached result#1120
Merged
Conversation
Reading a numeric formula cell returned 0 for files whose cached formula result was not stored (e.g. legacy .xls produced by tools that write the formula but leave the cached value at 0). POI does not recalculate on read: getNumericCellValue() returns the cached result, so the cell read as 0. The same content saved as .xlsx worked only because Excel had stored the computed cache. Resolve the value with a FormulaEvaluator for FORMULA cells, falling back to the cached value if evaluation is not supported by POI (NotImplementedException). evaluate() does not mutate the cell/cache, so it is safe on read. Applied to getNumber() (which also feeds getValue()) in the HSSF and XSSF ExcelCells of the gxoffice (ExcelDocument) API.
Collaborator
Cherry pick to beta success |
iroqueta
added a commit
that referenced
this pull request
Jun 8, 2026
Reading a numeric formula cell returned 0 for files whose cached formula result was not stored (e.g. legacy .xls produced by tools that write the formula but leave the cached value at 0). POI does not recalculate on read: getNumericCellValue() returns the cached result, so the cell read as 0. The same content saved as .xlsx worked only because Excel had stored the computed cache. Resolve the value with a FormulaEvaluator for FORMULA cells, falling back to the cached value if evaluation is not supported by POI (NotImplementedException). evaluate() does not mutate the cell/cache, so it is safe on read. Applied to getNumber() (which also feeds getValue()) in the HSSF and XSSF ExcelCells of the gxoffice (ExcelDocument) API. (cherry picked from commit baa2633)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reading a numeric formula cell from an Excel file returned 0 when the file did not have the formula's cached result stored. This is common in legacy
.xlsfiles produced by tools/systems that write the formula but leave the cached value at0.POI does not recalculate formulas on read:
getNumericCellValue()returns the cached result, so the cell reads as0. The same logical content saved as.xlsxworked only because Excel had stored the computed cache.Evidence (real customer files, POI 5.4.1)
.xlscached.xlsxcached=D2=D3It is not an
.xls-vs-.xlsxformat issue: both behave the same when the cache is missing. Evaluating the formula returns the correct value for both.Change
For
FORMULAcells, resolve the numeric value with aFormulaEvaluator, falling back to the cached value when evaluation is not supported by POI (NotImplementedException).evaluate()does not mutate the cell or the cached value, so it is safe on read.Applied in
getNumber()(which also feedsgetValue()) of the HSSF and XSSFExcelCellsin thegxoffice(ExcelDocument) API:com/genexus/gxoffice/poi/hssf/ExcelCells.javacom/genexus/gxoffice/poi/xssf/ExcelCells.javaNotes