Skip to content

feat(xlsx): data validation lists: a dropdown at the cell, other values refused - #67

Open
Alex-Citeroni wants to merge 2 commits into
p10node:mainfrom
Alex-Citeroni:feat/xlsx-validation
Open

Alex-Citeroni wants to merge 2 commits into
p10node:mainfrom
Alex-Citeroni:feat/xlsx-validation

Conversation

@Alex-Citeroni

@Alex-Citeroni Alex-Citeroni commented Dec 4, 2026 •

Copy link
Copy Markdown

A cell with a list of allowed values (<dataValidation type="list">) was edited like any other: no dropdown, and any value went in. The selected cell now shows its list, and a value outside it is refused when typed, if the file says so.

What it does

  • Reading: all of a sheet's <dataValidations> are read. A list can come from values typed in the rule, a range (also of another sheet), a defined name, or a formula that gives a range.
  • In the view: a button at the selected cell opens its list (Alt+Down too; arrows, Enter, Escape). A dialog, from the toolbar or the context menu, gives the selected cells a list, edits it or takes it away.
  • Refusing: xlsx.set takes validate: true, which the view gives for what is typed. A value outside a list that stops fails with the file's own message, and nothing changes. Without the option every value goes in, as before.
  • Operations: validate is one step of Undo, and one operation in a room. The rules follow rows and columns, also those of the sheet that holds the values, and sheets renamed or deleted.
  • Saving: in the order of the schema. A rule that was not edited keeps its own XML; only its range and formulas follow the rows and columns. What a newer Excel keeps in the extension list stays as it is.

It also fixes a small thing in rooms: an operation refused locally (a sort over merged cells) left a step of Undo that did nothing. Undo and Redo now stay as they were.

XlsxToolbar takes onValidation, optional: without it, it has no Data validation button.

Limits

  • Only typing is checked: in the cell, in the formula bar, and Ctrl+Enter. A paste, a fill, a replace, formula results and other people's edits are not.
  • A refused value comes back in its cell once, to be put right, with a message. Entered again unchanged, it is let go. Warning and information rules let the value in.
  • The other kinds of rule (whole number, date, text length, custom…) are kept in the file and not enforced. The input message is not shown.
  • A validation does not travel with copied cells.
  • INDIRECT of a defined name, common for dependent dropdowns, gives an empty list and refuses nothing, because the formula engine does not read it. INDIRECT of a cell address works.

Tests

Unit tests for reading, refusing, undo, collaboration and the saved XML, and an e2e spec for the dropdown and the dialog. Typecheck and the unit suite (1785) pass. The xlsx e2e suite (65, run with both PRs merged) passes. N1-014 is flaky there, as it is on main without this change. I have not opened a saved file in desktop Excel.

The strings are in English and German. The filter by values is a separate PR. The two are independent, but they touch some of the same files: I will rebase whichever lands second.

🤖 Generated with Claude Code

…tside the list refused when typed, set from a dialog, saved

- the file's <dataValidations> are read, all of them; a list is understood: values typed in the rule, a range (also of
  another sheet), a defined name or a formula that gives one, read through the calc engine. The other kinds (whole,
  decimal, date, time, textLength, custom) are kept as read and written back, not enforced
- the selected cell shows a button that opens its list (Alt+Down too: arrows, Enter, Escape); the value picked goes in
  as one typed does, a date or a percentage showing as one
- `xlsx.set` takes `validate: true`, which the view gives for what is typed (in the cell, in the formula bar, Ctrl+Enter):
  a value outside a list that stops fails with the file's message, nothing changed. Without it every value goes in, as
  before: a paste, a fill and a replace are not checked. `xlsx.refused` asks without setting, `xlsx.listValues` is the list
- `validate` sheet operation and its dialog (toolbar, context menu): a list for the selected cells, edited or taken away.
  One step of Undo; in a room one operation, which follows the rows and columns moved meanwhile, its source too, and
  whose Undo leaves the validations others set on other cells
- the rules follow rows and columns, also those of the sheet that holds the values, and sheets renamed or deleted
- saved in the order of the schema; what a newer Excel keeps in the extension list stays as it is
- an operation refused here leaves no step of Undo in a room (a sort over merged cells did)
- `XlsxToolbar` takes `onValidation`, optional: without it, it has no Data validation button

Not here: enforcing the other kinds, the input message of a rule, a validation copied with its cells, the lists of the
extension list, INDIRECT of a defined name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierreneter

Copy link
Copy Markdown
Member

Thank you for this, @Alex-Citeroni. It is careful work. I traced these paths and they hold:

  • a refused value changes nothing, in the engine and in a room;
  • the rules follow rows and columns, on their own sheet and on the sheet that holds the values;
  • sheets renamed and deleted;
  • the new validate operation, in every place of src/collab that switches on an operation.

One thing has to be fixed before this goes in, and three smaller ones are worth a look. I read the code. I have not run it, and I have not opened a saved file in Excel.

To fix before merge

Writing <dataValidations> from the model changes rules that were not edited.

  • The reader keeps every attribute of a <dataValidation> except sqref (src/core/xlsx/workbook.ts:358-363). But the SAX reader drops the prefix of an attribute unless it is a relationship's (src/core/xml.ts:310-319), so the xr:uid="{…}" that current Excel writes on a rule arrives as uid.
  • validationsXml writes every entry of v.a back (src/core/xlsx/validation.ts:175-186). The saved rule then has uid="{…}", which is not an attribute of CT_DataValidation. I expect Excel to offer to repair such a file.
  • It takes little to get there. Inserting or deleting a row or a column on a sheet that has any rule sets dirtyValidations (src/core/xlsx/structure.ts:284-287), also when no rule moved, and the whole element is then written from the model. On main the same edit goes through followSheetTail, which moves sqref in the file's own XML and leaves the rest of the element as it was.
  • The same rewrite loses what the reader skipped: a rule whose sqref has no range that parseSqref accepts, and the rules past MAX_VALIDATIONS, are not in the model, so they are not written back.

Two ways to fix it: keep the attribute names as the file wrote them (or write only the attributes CT_DataValidation has), or, better, write from the model only the rules that changed and leave the others to followSheetTail as before. A fixture with xr:uid on a rule, saved after a row is inserted, would cover it.

Smaller, not blocking

  • Redo is lost when an operation is refused in a room. XlsxCollab.local empties redoStack before submit (src/collab/xlsx.ts:132), and the new catch takes back only the undo entry. Outside a room a refused set throws before the history is touched.
  • Taking a list away where there is none leaves an undo step in a room. validate with rule: null returns early (src/core/xlsx/editor.ts:1356-1357, "nothing to take away"), but local has already pushed its entry, and nothing was refused, so the entry stays and undoes nothing.
  • After a refusal the editor is closed and the selection has moved on. You list the lost text as a limit, which is fine for this PR. Keeping the cell in edit mode, as Excel does, would be the natural next step.

#66 changes eight of the same files, so whichever of the two lands second needs the rebase you mentioned.

…as them; a refused value stays in its cell

- a rule keeps its own element when rows or columns move: the attributes of a newer Excel, rules that do not read
- a value the list does not take is back in its cell, to be put right
- in a room, what is refused or changes nothing leaves Undo and Redo as they were

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alex-Citeroni

Copy link
Copy Markdown
Author

Thank you, this was a real one: I reproduced the invalid uid in a saved file. Everything you listed is fixed in aa2f230.

To fix before merge

I took your second option. A rule that was not edited keeps its own XML element, and only its sqref and the references in its formulas follow the rows and columns. So xr:uid stays as the file wrote it, and the rules the reader skips are written back. A rule that was edited is written with the attributes of CT_DataValidation only. A test saves a file with xr:uid on a rule after a row is inserted.

Smaller

  • Undo and Redo in a room: an operation that is refused, or that changes nothing (a list taken away where there is none), leaves both as they were.
  • After a refusal: the value comes back in its cell once, to be put right. If it is entered again unchanged, it is let go, so nobody gets stuck there.

The unit suite passes. I still have not opened a saved file in desktop Excel.

I will rebase whichever of the two lands second.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants