Repository navigation
Feature/take function - #1722
Conversation
✅ Deploy Preview for hyperformula-dev-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
hyperformula-docs | df4c98d | Commit Preview URL Branch Preview URL |
Nov 16 2026, 12:49 PM |
Performance comparison of head (df4c98d) vs base (399c25c) |
TAKE shipped with the English name in 10 of 16 packs while 6 carried a
translation, and VSTACK/HSTACK were English in all 16. Microsoft localizes
all three in most locales, so a user could not type the name their Excel
uses.
Names taken from Microsoft's localized "Excel functions (alphabetical)"
page, one locale at a time. Each row there links to the function's own page
using the English slug in the href while the link text is the localized
name, so the lookup is exact:
<a href="functions/take-function">WYCINEK</a>
Left as English where Microsoft itself does not translate: TAKE, VSTACK and
HSTACK in Indonesian, and VSTACK/HSTACK in Swedish.
Note that a function's own localized page is not a usable source: for
several locales its syntax block still shows the English name even though
the prose and argument names are translated (the French page shows
"=TAKE(tableau, lignes,[colonnes])" while the product uses PRENDRE).
DEV_DOCS records the lookup method and adds the governing policy: ship a
localized name only when it can be confirmed against the product, and keep
the English name otherwise, since an invented name matches nothing, reads
plausibly enough to be typed first, and fails as #NAME?.
No changelog entry: TAKE, VSTACK and HSTACK are all still in [Unreleased],
so no wrong name has been released.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
blocking: browser-tests fails on 6d0464d: Karma stops at TypeError: it.each is not a function from line 471 of function-take.spec.ts in tests#28, after 1206 of 6789 specs in Chrome. The fix belongs in tests#28; see the comment there.
nit: the description still says "86/86 focused TAKE tests passed" and "503/503 Jest suites passed (6,319 tests passed, 3 skipped)"; function-take.spec.ts in tests#28 has 99 tests now, and the suite totals predate three develop merges. Worth re-running or dropping them.
# Conflicts: # CHANGELOG.md # hyperformula/src/license/functionCapabilities.ts
…lumn Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
### Context An array formula whose result is a whole column or a whole row, such as `=SORT(Data!A:A)` or `=FILTER(Data!A:A, Data!A:A>0)`, only fits at the matching sheet edge. Placed anywhere else, it has no room to spill. Before this PR, the error depended on how the formula reached the cell: | How the formula is entered | Result | |---|---| | `buildFromSheets` / `buildFromArray` | `#SPILL!` "No space for array result." | | `setCellContents` | `#ERROR!` "Parsing error. Invalid range size." | The second result is misleading: the formula parses fine. Cause: `DependencyGraph.exchangeOrAddFormulaVertex` builds the result area with `AbsoluteCellRange.spanFrom`, which throws when an unbounded area can't be placed. The catch in `Operations.setCellContent` (added in #1311 to stop the runtime exception from #1267) stores that throw as a parsing error. The build path uses `spanFromOrUndef` in `setAddressMappingForArrayVertex` and reaches the normal space check, which returns `#SPILL!`. This PR makes `exchangeOrAddFormulaVertex` use `spanFromOrUndef` and skip the result-area mapping when the area can't be placed, like the build path. It also marks the vertex as no-space (`setNoSpace`) right away. That puts it in the state the build path reaches after evaluation: a one-cell `#SPILL!` array. Without that step, clearing or overwriting the cell while evaluation is suspended (`suspendEvaluation` or `batch`) would call `getRange` on the unbounded vertex and crash. The formula is stored and evaluates to `#SPILL!`. Arrays that can be placed, and non-array formulas, are unchanged. `#SPILL!` is also what Excel shows for a whole-column result that can't fit (measured in Excel Online for `TAKE` and `DROP` whole-column results placed below the first row). #1311 changed a runtime exception into a cell error, and that still holds. Only the error changes, to the `#SPILL!` the build path already returns. ### How did you test your changes? - Tests: handsontable/hyperformula-tests#73. - The two `setCellContents` tests in `ranges.spec.ts` that expected `#ERROR!` "Invalid range size" for `=A:A+B1` and `=A:A+1:1` now expect `#SPILL!`, matching the build-path tests next to them. - New tests for FILTER and SORT over a whole column entered below the first row: - the result is `#SPILL!`, and the formula is stored; - no cells below are reserved; - undo restores the previous value, and redo returns `#SPILL!`; - clearing it while evaluation is suspended, and overwriting it inside a `batch`, both work; - it is `#SPILL!` after evaluation resumes, and stays `#SPILL!` when its source changes; - control: the same function over a bounded range still spills normally. - On `develop`, 7 of those tests fail: every test that expects `#SPILL!`. With this PR, all 19 tests in `ranges.spec.ts` pass. With only the first commit (no `setNoSpace`), the suspended-clear and `batch` tests crash. That is the case Cursor Bugbot reported on this PR. - An additional script compared engines built both ways through the same 9 steps (initial, edit another cell, insert rows, remove rows, undo, redo, move the formula to A1, clear, undo the clear) for FILTER and SORT over a whole column. It also covered `DROP` and `TAKE` whole-column results, run on the #1796 branch. With this fix, the two paths returned identical results at all 54 steps. Before it, every step that left the formula below the first row differed. - Full Jest suite: 502/502 suites, 6,244 tests passed, 3 skipped. `tsc --noEmit` passes, and lint reports no new warnings in `DependencyGraph.ts`. ### Types of changes - [ ] Breaking change (a fix or a feature because of which an existing functionality doesn't work as expected anymore) - [ ] New feature or improvement (a non-breaking change that adds functionality) - [x] Bug fix (a non-breaking change that fixes an issue) - [ ] Additional language file, or a change to an existing language file (translations) - [ ] Change to the documentation ### Related issues: 1. Follow-up to #1311 / #1267. 2. Found while reviewing #1796, which adds `DROP`. `DROP` and `TAKE` (#1722) go through the same path. 3. Tests: handsontable/hyperformula-tests#73 ### Checklist: - [x] I have reviewed the guidelines about [Contributing to HyperFormula](https://hyperformula.handsontable.com/docs/guide/contributing.html) and I confirm that my code follows the code style of this project. - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] My change is compliant with the [OpenDocument](https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part4-formula/OpenDocument-v1.3-os-part4-formula.html) standard. - [x] My change is compatible with Microsoft Excel. - [ ] My change is compatible with Google Sheets. - [x] I described my changes in the [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/master/CHANGELOG.md) file. - [ ] My changes require a documentation update. - [ ] My changes require a migration guide. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches array-formula graph setup on every `setCellContents` edit; behavior change for callers that relied on the old `#ERROR!` message, but bounded arrays and non-array formulas are unchanged. > > **Overview** > **`setCellContents`** now reports **`#SPILL!`** (not **`#ERROR!` / "Invalid range size"**) when an array formula’s whole-column or whole-row result cannot fit at the entry cell—e.g. **`=SORT(A:A)`** below row 1—matching **`buildFromSheets`** and Excel. > > In **`DependencyGraph.exchangeOrAddFormulaVertex`**, the spill area is computed with **`spanFromOrUndef`** instead of **`spanFrom`**, so an unplaceable unbounded result no longer throws and gets misclassified as a parse error. When no range can be placed, array vertices are marked **`setNoSpace()`** immediately and spill mapping is skipped, avoiding crashes when clearing or overwriting the cell during **`suspendEvaluation`** or **`batch`**. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5b19c60. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
My 2 November request for changes stands until #1876 is in develop and merged here, since at 00e6379 the three layouts in the ArrayPlugin.ts:460 thread still throw from buildFromArray. With 1, 2, 3 in A1:C1, =SUM(TAKE(1:1,,-2)) gives 5 at this head and 0 in Excel, as the new whole-row row says. The it.each fix in hyperformula-tests#28 holds, and browser-tests passed on 00e6379 with it.
Low severity, high confidence: TAKE needs the same setCellContents spec as CHOOSECOLS in #1734. Over 1 to 5 in A1:A5, =TAKE(A:A,,1) entered in H5 with setCellContents returns #ERROR! "Invalid range size" at 00e6379 and #SPILL! with develop merged locally, and no spec enters a whole-column TAKE that way.
Low severity, high confidence: the description still says "86/86 focused TAKE tests" and "503/503 Jest suites", while function-take.spec.ts has 99 tests now.
Below the first row, TAKE returned #SPILL! for any count read from a cell when the whole-column or whole-row source was on the formula's own sheet, because a larger result used to throw. A result taller or wider than its reserved area now returns #SPILL! on its own, so the guard is no longer needed: counts that fit spill, as in Excel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
blocking: the description needs the current template, whose AI assistance section the Definition of Done asks for when an AI tool wrote a substantial part of a change; 5 of this pull request's 33 non-merge commits are co-authored by Claude, and the How did you test your changes, Compatibility, Public API changes, Out of scope and Related issues sections are missing too. It is the only blocking item left.
question: getFunctionDetails('TAKE') reports rows as optional while =TAKE(A1:C3) returns #N/A "Wrong number of arguments", as Bugbot found in hyperformula-tests#28; should the details report rows as required?
suggestion: a spec could enter =TAKE(A:A,,1) in H5 with setCellContents, as hyperformula-tests#34 now does for CHOOSECOLS; it returns #SPILL! here and no TAKE spec covers it.
At 6b4b1c0 the three layouts from the ArrayPlugin.ts:454 thread build and return #SPILL!, the MATCH layout returns #N/A, and =TAKE(A:A,B1) in C5 with B1 = 2 spills 1, 2. The four new specs for counts that fit fail on a2e1980 and pass here, and the description's test counts match my runs. e2e failed twice before any test ran because the runner could not install the browsers, so a re-run should clear it.
An empty rows argument still keeps every row, as in Microsoft Excel; it is now detected in the method instead of through a default value, which made getFunctionDetails report the argument as optional. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
|
Updated the description to the current template. On |
marcin-kordas-hoc
left a comment
There was a problem hiding this comment.
getFunctionDetails('TAKE') now reports rows as required, =TAKE(A1:C3) still returns #N/A, and an empty rows keeps every row; the layouts I probed give the same results as at 6b4b1c0. The new metadata pin fails on 6b4b1c0, and forcing the empty-rows check off fails 19 of the 107 TAKE tests, as the description says. The setCellContents spec is in, the description follows the template, and CI passed at ab5fc64, e2e included, with 7,327 tests.
Dismissing: the review flow moved to Marcin, who approved this PR on 2026-11-13.
# Conflicts: # CHANGELOG.md # docs/guide/list-of-differences.md # hyperformula/src/interpreter/plugin/ArrayPlugin.ts # hyperformula/src/license/functionCapabilities.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1722 +/- ##
===========================================
+ Coverage 97.47% 97.49% +0.01%
===========================================
Files 210 210
Lines 16903 17036 +133
Branches 3809 3841 +32
===========================================
+ Hits 16477 16610 +133
Misses 418 418
Partials 8 8
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Note
Medium risk: Adds a new built-in TAKE function with an additive Interpreter method and (per the description) changes to shared static spill-size prediction; the new function itself is contained, but the size-prediction path is used by all array functions, so a defect there could affect existing spill behaviour.
Full review: no issues found.
Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).
…feature/hf-384-drop # Conflicts: # hyperformula/src/interpreter/plugin/ArrayPlugin.ts # hyperformula/src/license/functionCapabilities.ts
### Context Microsoft Excel returns `#CALC!` when a function cannot calculate its result, most often when the result would be an empty array. HyperFormula had no such error and returned `#N/A` or `#VALUE!` in those cases. This adds `ErrorType.CALC` and switches the functions where Excel returns it: | Function | Case | Before | After | |---|---|---|---| | `FILTER` | No value meets the conditions | `#N/A` | `#CALC!` | | `UNIQUE` | Nothing is kept (`exactly_once` is `TRUE` and every row or column repeats) | `#N/A` | `#CALC!` | | `SEQUENCE` | Rows or columns truncate to 0 (`0`, `0.5`, `FALSE()`, a blank cell) | `#VALUE!` | `#CALC!` | | `CONCAT`, `TEXTJOIN` | The result is longer than 32,767 characters | `#VALUE!` | `#CALC!` | This is a breaking change, so it targets 4.0.0: - `TranslationPackage` validates error keys exhaustively, so a custom language pack without `errors.CALC` makes `registerLanguage()` throw a `MissingTranslationError`. - `IFNA()` and `ISNA()` no longer catch the errors listed above. `ERROR.TYPE` returns `14` for `#CALC!`, the number Excel uses. Each built-in language pack gets the name Excel uses in that language, for example `#OBL!` (Polish), `#HESAPLA!` (Turkish), `#KALK!` (Swedish); German, French, Dutch and several others keep `#CALC!`. The names were checked in Microsoft Excel Online set to each language. Microsoft's localized "How to correct a #CALC! error" pages are not reliable for this (the Finnish, Portuguese and Russian pages say `#CALC!` where Excel shows `#LASKE!`, `#CÁLC!` and `#ВЫЧИСЛ!`, and the Danish and Dutch pages give names Excel doesn't use), so `dev-docs/I18N.md` now says to confirm every error name in Excel. The `hyperformula-ui` formula lexer now recognises `#CALC!`, so the editor no longer marks it as invalid. `SORT` keeps `#N/A` for an empty input. Excel never returns `#CALC!` there: `SORT` of an empty column returns blank rows. HyperFormula's branch only guards a zero-width sheet. `SEQUENCE` now checks for a row count above `maxRows` before checking for a dimension of 0, and for a column count above `maxColumns` after it. This is the order Excel follows: `=SEQUENCE(2000000,0)` is `#VALUE!`, `=SEQUENCE(0,20000)` is `#CALC!`. ### How did you test your changes? - `npx jest` in `hyperformula/` with the paired `hyperformula-tests` branch `feat/hf-134-calc-error` (handsontable/hyperformula-tests#118): 539 suites, 8,379 tests passed. - `npx tsc --noEmit`, and `eslint` on the changed files: no errors. - `npm run docs:build`: passes, including the new migration guide. ### AI assistance Claude Code wrote parts of the code, tests and docs, and ran the Excel comparison. ### Compatibility with Excel and Google Sheets Checked in Microsoft Excel Online: | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=FILTER({1;2;3},{1;2;3}>5)` | `#CALC!` | Not checked | `#CALC!` | | `=UNIQUE({1;1;2;2},,TRUE())` | `#CALC!` | Not checked | `#CALC!` | | `=SEQUENCE(0)`, `=SEQUENCE(0.5)`, `=SEQUENCE(1,0)` | `#CALC!` | Not checked | `#CALC!` | | `=SEQUENCE(-1)`, `=SEQUENCE(0,-1)` | `#VALUE!` | Not checked | `#VALUE!` | | `=SEQUENCE(2000000,0)` | `#VALUE!` | Not checked | `#VALUE!` | | `=CONCAT(REPT("a",32767),"b")` | `#CALC!` | Not checked | `#CALC!` | | `=TEXTJOIN("",FALSE(),REPT("a",32767),"b")` | `#CALC!` | Not checked | `#CALC!` | | `=IFNA(FILTER({1},{0}),"x")` | `#CALC!` | Not checked | `#CALC!` | | `=ISERR(FILTER({1},{0}))` | `TRUE` | Not checked | `TRUE` | | `=ERROR.TYPE(FILTER({1},{0}))` | `14` | Not checked | `14` | | `=SORT(A:A)` on an empty column | blank rows | Not checked | blank | Added to `list-of-differences.md`: empty text used as a number (`=""+1`, `=ABS("")`, `=SEQUENCE("")`) is `#VALUE!` in Excel. HyperFormula reads it as `0`, so `=SEQUENCE("")` now returns `#CALC!`. ### Public API changes - `ErrorType.CALC` added. - `RawTranslationPackage.errors` must include `CALC`. ### Out of scope and follow-ups - `TAKE` (#1722), `DROP` (#1796), `TOROW`/`TOCOL` (#1828), and `WRAPROWS`/`WRAPCOLS`/`EXPAND` (#1830) return `#N/A` for an empty result while they wait for this error type. Whichever of those PRs and this one merges second switches them to `#CALC!`. ### Types of changes - [x] Breaking change (existing functionality no longer works as before) – agreed with the maintainers - [ ] New feature or improvement (a non-breaking change that adds functionality) - [ ] Bug fix (a non-breaking change that fixes an issue) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. Fixes #1647 (HF-134) ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [ ] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [x] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [x] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > Breaking error semantics across array and text functions and mandatory i18n keys will change formula results and can break custom language packs and error-handling logic on upgrade. > > **Overview** > Adds **`ErrorType.CALC`** (`#CALC!`) as a breaking 4.0 change so HyperFormula matches Excel when a function cannot produce a result—especially empty arrays or oversized text. > > **`FILTER`**, **`UNIQUE`** (empty result), **`SEQUENCE`** (truncated row/column count of 0), and **`CONCAT`** / **`TEXTJOIN`** (over 32,767 characters) now return **`#CALC!`** instead of **`#N/A`** or **`#VALUE!`**. **`IFNA()`** and **`ISNA()`** no longer handle these cases; callers need **`IFERROR()`** / **`ISERROR()`** or explicit **`ErrorType.CALC`** checks. **`SEQUENCE`** also reorders validation so oversized row counts are checked before zero-dimension **`#CALC!`**, like Excel. > > All built-in language packs gain localized **`errors.CALC`** strings; **`registerLanguage()`** throws **`MissingTranslationError`** if a custom pack omits **`CALC`**. Docs include a **3.x → 4.0** migration guide, updated error/compatibility pages, and changelog entry. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3166a31. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
### Context This PR adds the `TRIMRANGE` dynamic-array function (HF-391). `TRIMRANGE(range, [trim_rows], [trim_cols])` returns a range without the blank rows and columns at its edges. > [!IMPORTANT] > **Stacked on #1796 (`DROP`).** #1722 (`TAKE`) has merged. Until #1796 merges, this diff also shows its commits. Once it merges, `develop` will be merged into this branch and only these changes will remain in the diff. Behavior, checked against Microsoft Excel Online (en-US): - Each trim code is 0 (none), 1 (leading), 2 (trailing) or 3 (both, the default). Fractions, other numbers, text and `""` return `#VALUE!`; numeric text and `TRUE`/`FALSE` are accepted. - In a range, only an empty cell is blank. Formulas, empty text, 0, `FALSE`, errors and spaces are content, and blank cells inside the result stay blank. - A source with nothing left to keep returns `#REF!`. ### Implementation - `TRIMRANGE` lives in `ArrayPlugin`, after `TAKE`. Codes are read as single values and coerced in the method, so errors are reported in Excel's order. - The edges are found by scanning inward, so the cost is the blank border, not the whole range. - The whole-column rule is now one helper shared with `TAKE`. `TAKE`'s results are unchanged. - Included: the catalogue entry, the license table entry, the name in every language pack, the changelog and `list-of-differences.md` rows. Localized names come from Excel Online in each locale; Indonesian keeps the English name. ### How did you test your changes? - Tests PR: handsontable/hyperformula-tests#103, 142 tests from 143 cases measured in Microsoft Excel Online (en-US), plus scenario tests. - Full Jest suite after merging the current `feature/hf-384-drop`, which includes `develop`: 541 suites, 8,589 tests passed, 3 skipped. `TAKE` gave identical results on 540 probes before and after the shared helper. - Ten deliberate breaks of the code each failed tests, for example 37 when leading columns were not trimmed. - `npm run compile`, `npm run docs:generate-function-docs` and `git diff --check` pass. Lint shows no warnings on new lines. ### AI assistance Claude Code wrote the code, tests and docs. I reviewed it. ### Compatibility with Excel and Google Sheets Excel: Microsoft Excel Online (en-US). Google Sheets has no `TRIMRANGE` function. In the examples, A1:E6 holds 1, 2, 3 / 4, blank, 6 / 7, 8, 9 in B2:D4 with blank cells around it, O1:O4 is blank, and Q1:Q5 holds a blank cell, `=""`, 5, `=""` and a blank cell. | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=ROWS(TRIMRANGE(A1:E6))` | 3 | No such function | 3 | | `=TRIMRANGE(A1:E6,4)` | `#VALUE!` | No such function | `#VALUE!` | | `=TRIMRANGE(A1:E6,1.5)` | `#VALUE!` | No such function | `#VALUE!` | | `=ROWS(TRIMRANGE(O1:O4))` | `#REF!` | No such function | `#REF!` | | `=COUNTA(TRIMRANGE(Q1:Q5))` | 3 | No such function | 3 | Deliberate differences, listed in `list-of-differences.md`: | Case | HyperFormula | Excel | |---|---|---| | Result size | The untrimmed range is reserved; the result fills its top-left corner, the rest stays blank | Spills only the trimmed result and follows the data | | Whole column or row | Spills from the first row or column only, with the sheet's current size | Spills from any row | | Array or range as a trim code | One `#VALUE!` | An array of `#VALUE!` | | Result type | Values | A reference (`ISREF` is TRUE) | | `A1:.C10` trim references | Parse error | Supported | ### Public API changes None. One new built-in function. ### Out of scope and follow-ups The trim-reference syntax (`A1:.C10`) is not parsed; it needs parser support beyond this function. ### Types of changes - [ ] Breaking change (existing functionality no longer works as before) – agreed with the maintainers - [x] New feature or improvement (a non-breaking change that adds functionality) - [ ] Bug fix (a non-breaking change that fixes an issue) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. HF-391 (`TRIMRANGE`). 2. Depends on #1796 (`DROP`). 3. Tests: handsontable/hyperformula-tests#103 ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [ ] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Large changes to array spill sizing and evaluation in the core interpreter path; incorrect prediction could cause wrong spill areas or `#SPILL`/`#N/A` behavior across dependent sheets. > > **Overview** > Adds Excel-style dynamic-array functions **`TAKE`**, **`DROP`**, and **`TRIMRANGE`** in `ArrayPlugin`, with evaluation, static spill-size prediction, and shared helpers for whole-column/row sources and sheet-edge placement (`sizeAtSheetEdge`, literal count parsing). > > **`TRIMRANGE`** trims blank edge rows/columns (configurable codes 0–3), scans content without reading whole ranges, reserves the full source footprint for spill (trimmed data in the top-left), and returns values rather than references. **`TAKE`** / **`DROP`** slice sources by row/column counts (including negative “from end” semantics); zero counts yield `#N/A` via new `ErrorMessage.ZeroRowOrColumnCount`. > > Spill behavior differs from Excel where documented: errors and cell-dependent counts fill or reserve the predicted array area (`#SPILL` when sizing runs before evaluation). **`Interpreter.isFunctionImplementedBy`** supports static analysis of count expressions (e.g. `TRUE`/`FALSE`). > > Also updates function metadata, license allowlists, localized names across language packs, **CHANGELOG**, and **`list-of-differences.md`** (including general rows on array errors and dynamic sizing). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7054e1d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Kuba Sekowski <kuba.sekowski.dev@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Kuba Sekowski <jakub.sekowski@handsontable.com>
…1830) ### Context This PR adds the `WRAPROWS`, `WRAPCOLS` and `EXPAND` dynamic-array functions (HF-390, HF-389, HF-386). `WRAPROWS(vector, wrap_count, [pad_with])` and `WRAPCOLS(vector, wrap_count, [pad_with])` wrap a row or column of values into rows or columns of `wrap_count` values. `EXPAND(array, rows, [columns], [pad_with])` pads an array to the given numbers of rows and columns. > [!IMPORTANT] > **Stacked on #1796 (`DROP`).** The three functions reuse the count parser and the whole-column size helper that #1796 and #1722 (merged) introduce, so this branch is based on `feature/hf-384-drop`. Until #1796 merges, this diff also shows its commits. Once it merges, `develop` will be merged into this branch and only these changes will remain in the diff. Behavior, checked against Microsoft Excel Online (en-US): - `WRAPROWS` fills rows and `WRAPCOLS` fills columns, in the vector's order; a row and a column vector give the same result. The last line is padded with `pad_with`, or with `#N/A` when the `pad_with` argument is omitted or left empty; a reference to an empty cell pads with blank cells, as in Excel. A `wrap_count` at least as large as the vector returns the vector at its own length, without padding. - `pad_with` can be any value, including an error or a blank cell, and is used only for padded cells: an error in `pad_with` never becomes the result. - `wrap_count` is truncated toward zero; a value below 1 (including `FALSE`, `0.5` and a blank cell) returns `#NUM!`. Numeric text, percentages and `TRUE` are accepted; `""`, an empty-text cell and other text return `#VALUE!`. - A two-dimensional `vector`, an empty `vector` argument and a blank one-cell `vector` return `#VALUE!`. Errors are reported in this order: the vector's error, the count's error or coercion, the vector's shape, then the count's range. - `EXPAND` pads with `pad_with`, with `#N/A` when it is omitted, and with blank cells when it is empty. An omitted or empty `rows` or `columns` keeps the array's size. Counts are truncated toward zero and coerced as `wrap_count`; a count smaller than the array returns `#VALUE!`, and more than 1,048,576 rows return `#NUM!`. An array or a range as `pad_with` returns `#VALUE!`. - Errors and blank cells inside the source stay elements of the result. Scalars, inline arrays, ranges and computed arrays are accepted as sources. The result is a value, not a reference, as in Excel. Differences from Excel, listed in `list-of-differences.md` unless noted: - A count read from a cell, or given as an array, makes the formula a single cell, as for `SEQUENCE`: the result's size must be known before the formula is evaluated, so a larger result returns `#VALUE!`. A one-cell result and every error are shown as in Excel. Excel wraps or expands by the cell's value, and lifts an array count into one result per element. - An array as `pad_with` in `WRAPROWS` and `WRAPCOLS` uses its first value; Excel returns one result per element. A two-cell range as a count or as `pad_with` returns `#VALUE!` when the formula is outside the range's rows; Excel lifts it as an array (not listed: a range where a single value is expected). - Whole-column and whole-row sources use the source sheet's current size, as in `TAKE` and `DROP`, and spill from the first row (or column) only; elsewhere they return `#SPILL!`, also for a whole column in column A below the first row and a whole row in the first row right of column A. `EXPAND` with an explicit `rows` pads a whole column to that many rows when the sheet is shorter; Excel counts all 1,048,576 rows and returns `#VALUE!`. - `EXPAND`, `WRAPROWS` and `WRAPCOLS` return `#VALUE!` for a result larger than the configured sheet size (the `maxRows` and `maxColumns` options), as `SEQUENCE` does, before building it. Excel returns the full result, for example 1,048,576 rows inside `ROWS`, or 20,000 columns for `=COLUMNS(WRAPCOLS(SEQUENCE(20000),1))`. #### Implementation - The three functions live in `ArrayPlugin`, after `TAKE`. `WRAPROWS` and `WRAPCOLS` share one implementation with the orientation as a parameter. - Counts are read as single values and coerced in the method, so that `""` returns `#VALUE!` and errors are reported in Excel's order. - Spill-size prediction uses literal counts and gives the exact size; a literal count that makes the function return an error returns that error instead of reserving space. A count that isn't a literal makes the formula a single cell (above). A source whose size can't be predicted before evaluation (a named expression), passed to `EXPAND` with a kept dimension, also makes it a single cell. - Whole-column and whole-row sources use the existing effective-size helper and `TAKE`'s placement rule. - VSTACK's row-padding helper takes an optional pad value, which the three functions use; VSTACK keeps padding with `#N/A`. - The function metadata catalogue entries, the changelog, and rows in `list-of-differences.md` are included. - Localized names were read from Excel Online in every locale by switching the session language and reading the formula bar. Indonesian keeps the English names, because Excel Online shows English function names in that locale. ### How did you test your changes? - Tests PR: handsontable/hyperformula-tests#98, branch `feature/HF-390`. It adds 126 `WRAPROWS`, 63 `WRAPCOLS` and 130 `EXPAND` tests, generated from 322 cases measured in Microsoft Excel Online (en-US) on the same data, plus tests for spill placement of whole columns and rows, counts read from cells, sources of unknown size and the configured sheet size. - Full Jest suite after merging the current `feature/hf-384-drop`, which includes `develop`: 543 suites, 8,766 tests passed, 3 skipped. The existing `TAKE`, `DROP`, `VSTACK` and `HSTACK` tests pass unchanged. - Breaking the code on purpose made the tests fail, for example: not capping a line at the vector's length failed 19 tests, not transposing `WRAPCOLS`'s predicted size failed 11, and accepting empty text as a count failed 7. The previous spill placement and the missing sheet-size check fail the 4 newest tests. - `npm run lint` reports no errors, and `npm run verify:typings` passes. ### AI assistance Claude Code wrote the code, tests and docs, and ran the Excel comparison. ### Compatibility with Excel and Google Sheets Checked in Microsoft Excel Online and Google Sheets, with 1 to 7 in A1:G1. Google Sheets has no `EXPAND` function. | Formula | Excel | Google Sheets | HyperFormula | |---|---|---|---| | `=WRAPROWS(A1:G1,3)` | `1, 2, 3; 4, 5, 6; 7, #N/A, #N/A` | same | same | | `=WRAPCOLS(A1:G1,3)` | `1, 4, 7; 2, 5, #N/A; 3, 6, #N/A` | same | same | | `=WRAPROWS({1,2,3},2,J1)`, J1 empty | `1, 2; 3, (blank)` | same | same | | `=WRAPROWS(K1,1)`, K1 = 0 | `0` | `0` | `0` | | `=EXPAND(A3:B4,3,3)`, 1, 2, 4, 5 in A3:B4 | `1, 2, #N/A; 4, 5, #N/A; #N/A, #N/A, #N/A` | No such function | same as Excel | | `=COLUMNS(WRAPCOLS(SEQUENCE(20000),1))` | `20000` | `20000` | `#VALUE!` (default `maxColumns` is 18,278) | The last row is a deliberate difference, listed in `list-of-differences.md` with the others above. ### Public API changes None. Three new built-in functions. ### Out of scope and follow-ups - Lifting an array count or an array `pad_with` into one result per element, as Excel does; HyperFormula sizes a spilled result before evaluating it. ### Types of changes - [ ] Breaking change (existing functionality no longer works as before) – agreed with the maintainers - [x] New feature or improvement (a non-breaking change that adds functionality) - [ ] Bug fix (a non-breaking change that fixes an issue) - [x] Additional language file, or a change to an existing language file (translations) - [x] Change to the documentation ### Related issues 1. HF-390, HF-389, HF-386. Depends on #1796 (`DROP`). 2. Tests: handsontable/hyperformula-tests#98 ### Checklist - [x] My pull request meets the [Definition of Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md). External contributors: see also [Contributing to HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html). - [x] I have signed the [Contributor License Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2). - [ ] I read my own diff end to end before requesting a review. - [x] I added a [CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md) entry, written by [the changelog rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog) – or none is needed (docs, tests or tooling only). - [x] I updated the documentation and JSDoc to match the change. - [ ] Breaking change only: I added a section to the migration guide. - [x] I updated the `dev-docs/` pages this change affects – or none needed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Large changes to array spill reservation and evaluation in `ArrayPlugin`; incorrect size prediction can cause wrong spill behavior or performance on whole-sheet references, though behavior is heavily documented and tested externally. > > **Overview** > Adds five Excel-style **dynamic-array** lookup functions in **`ArrayPlugin`**: **`TAKE`** and **`DROP`** slice sources by row/column counts; **`WRAPROWS`** / **`WRAPCOLS`** reshape 1-D vectors with optional padding; **`EXPAND`** pads arrays to target dimensions. > > Implementation centers on **static spill-size prediction** (same model as **`SEQUENCE`**): literal counts get exact footprints; cell-dependent counts, oversized results vs **`maxRows`**/**`maxColumns`**, and whole-column/whole-row sources only spill from row/column 1—otherwise **`#SPILL!`** or **`#VALUE!`**. Array errors fill the pre-reserved spill area. Shared helpers cover literal count parsing, effective source sizing, slicing, and optional **`padRowToWidth`** padding (also used by **`VSTACK`**). > > Also adds **`ZeroRowOrColumnCount`** for zero **`TAKE`** dimensions, **`Interpreter.isFunctionImplementedBy`** for static **`TRUE`/`FALSE`** in count parsing, function metadata and license capability entries, localized names across language packs, changelog entries, and **`list-of-differences.md`** rows documenting Excel/Sheets parity gaps. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3ad7f8d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Kuba Sekowski <kuba.sekowski.dev@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Kuba Sekowski <jakub.sekowski@handsontable.com>
Context
This PR adds the
TAKEdynamic-array function.TAKEreturns rows or columns from the beginning or end of an array and supports positive and negative counts, optional columns, syntactically empty argument slots, and array spilling.A row or column count that truncates to zero returns the existing
#N/Aerror with a TAKE-specific message. This is a documented Excel difference because HyperFormula does not expose a#CALC!error type.rowsis required, as in Excel, but may be left empty:=TAKE(A1:C3,,2)keeps every row. Omitting it returns the existing wrong-argument#N/Aerror, andgetFunctionDetailsreports it as required.Implementation:
#SPILL!below row 1. Below row 1, a count read from a cell spills when the result fits the area reserved for it, and returns#SPILL!when the result is taller. Finite counts are capped to configured sheet limits before allocation.How did you test your changes?
TAKEtests, plus theTAKEentry infunction-metadata-api.spec.ts.develop: 528 suites, 7,327 tests passed, 3 skipped.rowshandling fails 19 of theTAKEtests.npm run verify:typings,npm run lint(0 errors),npm run docs:generate-function-docsandgit diff --checkpass.AI assistance
Claude Code wrote the code, tests and docs. I reviewed it.
Compatibility with Excel and Google Sheets
Excel: Microsoft Excel Online. Google Sheets has no
TAKE. In the examples, A1:C3 holds 1 to 9 row by row.=TAKE(A1:C3,,2)=TAKE(A1:C3,,)=TAKE(A1:C3)#N/A=TAKE(A1:A3,0)#CALC!#N/AExcel also confirmed the same-sheet and cross-sheet whole-column behavior and the row-1 spill boundary. The deliberate differences (the zero count, whole-column and whole-row sources, a count read from a cell below row 1, an error count) are listed in
list-of-differences.md.Public API changes
None. One new built-in function.
Out of scope and follow-ups
#CALC!for a zero count needs the#CALC!error type (Add the #CALC! error type (HF-134) #1889).Types of changes
Related issues
TAKE).Checklist
dev-docs/pages this change affects – or none needed it.🤖 Generated with Claude Code
Note
Medium Risk
New dynamic-array spill and sizing logic in
ArrayPlugincan interact with whole-column references and spill placement; scope is additive but touches core array evaluation paths.Overview
Adds the Excel-style
TAKEdynamic-array function so formulas can return a sub-range from the start or end of a source array, with optional row/column counts, empty argument slots, and spill behavior.ArrayPluginnow implements evaluation (truncated counts, negative indices from the end, lazy sub-ranges for address-backed sources) andtakeArraySizespill prediction via static parsing of literal count expressions. A zero row/column count returns#N/Awith a newZeroRowOrColumnCountmessage (documented vs Excel’s#CALC!).Interpreter.isFunctionImplementedBysupports that static sizing path.TAKEis wired into function metadata, license capabilities, changelog, compatibility docs, and all language packs.Reviewed by Cursor Bugbot for commit 6b4b1c0. Bugbot is set up for automated code reviews on this repo. Configure here.