Skip to content

Fix XLOOKUP/VLOOKUP/HLOOKUP/MATCH #N/A before dimension - #2440

Merged
JanKallman merged 1 commit into
develop8from
bug/i2439
Jul 31, 2026
Merged

Fix XLOOKUP/VLOOKUP/HLOOKUP/MATCH #N/A before dimension#2440
JanKallman merged 1 commit into
develop8from
bug/i2439

Conversation

@swmal

@swmal swmal commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a regression introduced in 8.5.0 (still present in 8.6.3) where XLOOKUP, VLOOKUP, HLOOKUP and MATCH return #N/A when the lookup range starts before the first populated cell of the worksheet (lookupRange.Address.FromRow < Worksheet.Dimension.FromRow).

Root cause

In XlookupScanner, GetMaxItemsRow/GetMaxItemsColumns were changed to use GetAddressDimensionAdjusted(0) to avoid iterating over empty rows in open ranges (e.g. A:A). This clamps both ends of the range to the worksheet dimension and returns the clamped size as maxItems.

However, the scanning loop reads values with GetOffset(ix, 0), which is relative to the range's own FromRow/FromCol. When the dimension starts after the range start, maxItems becomes too small and the loop iterates over the empty leading rows, never reaching the actual data.

Fix

The scanner now tracks a startOffset (distance between the range's own start and the clamped start) and iterates GetOffset(startOffset + ix, ...), returning startOffset + ix as the result index.

This keeps the performance optimisation in both directions — leading empty rows and trailing empty rows are still skipped — while offset base and return index stay range-relative and correct. The fix is centralised in the scanner, so it covers all IRangeInfo implementations (RangeInfo, external and in-memory) without touching each GetAddressDimensionAdjusted.

…nsion; clamp both ends but keep range-relative offset
@swmal swmal self-assigned this Jul 27, 2026
@swmal swmal added the bug Something isn't working label Jul 27, 2026
@JanKallman
JanKallman merged commit c3e56f1 into develop8 Jul 31, 2026
3 checks passed
@JanKallman
JanKallman deleted the bug/i2439 branch July 31, 2026 06:29
JanKallman added a commit that referenced this pull request Aug 4, 2026
…2451)

* Fixes issue #2392 (#2419)

* Versioning moved to Directory.Build.props and Build-release.yml adjusted for v9

* Add link to security considerations for formulas

* Update link for security considerations in SECURITY.md

* Bug/s1060 (#2426)

* Allow AppVersion in OfficeProperties to be set to null. #2393.

* WIP

* bug/s1063 SEARCH function Range on third arg (#2430)

* Tracking down the issue

* Found main issue. Arrays 3rd arg Search function

* Simplified test

* #2431 Fix formula cfvo load error in ext icon sets (#2432)

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* Add configurable WrapText measurement to AutoFitColumns (#2427) (#2428)

* #2427 - Add WrappedTextAutofitMode enum for configurable WrapText measurement in AutoFitColumns; fix per-line East Asian width reset

* Added tests. Might be correct despite failing test

* Fixed failing test

---------

Co-authored-by: Ossian Edström <ossian.edstrom@epplussoftware.com>
Co-authored-by: Jan Källman <jan.kallman@epplussoftware.com>

* Added DisableImageFunctionDownloads property to ParsingConfiguration. If true the IMAGE function will not download external content (#2436)

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* EPPlus version 8.6.2

* Updated version number on EPPlus.Interfaces and EPPlus.System.Drawing projects

* Security updates 8.6.3 - System.Security.Cryptography.Xml (#2438)

* Added DisableImageFunctionDownloads property to ParsingConfiguration. If true the IMAGE function will not download external content

* Update System.Security.Cryptography.Xml to 8.0.4/9.0.18/10.0.10 for CVE-2026-47302/47304/50525/50527/50648. Bump version to 8.6.3.

* Additional fixes för appveyor8.yml, fixedIssures.md and EPPlus project file

---------

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* #2443 - Fix header/footer picture loss when copying worksheets (#2444)

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* #2439 - Fix lookup regression when range starts before worksheet dimension; clamp both ends but keep range-relative offset (#2440)

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* #2441 - Added DisableImageFunctionDownloads property to ExcelCalculationOption (#2442)

Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>

* Centralize version in Directory.Build.props; embed sub-project DLLs in package

---------

Co-authored-by: Jan Källman <jan.kallman@epplussoftware.com>
Co-authored-by: karlkallman <137038948+karlkallman@users.noreply.github.com>
Co-authored-by: OssianEPPlus <122265629+OssianEPPlus@users.noreply.github.com>
Co-authored-by: swmal <{ID}+username}@users.noreply.github.com>
Co-authored-by: Ossian Edström <ossian.edstrom@epplussoftware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants