Skip to content

feat: conditional formatting shown - #196

Merged
anderix merged 2 commits into
mainfrom
157-conditional-formatting
Nov 24, 2026
Merged

anderix merged 2 commits into
mainfrom
157-conditional-formatting

Conversation

@anderix

@anderix anderix commented Nov 24, 2026

Copy link
Copy Markdown
Member

Closes #157

  • doc/sheet/conditional.rs reads a table's calcext:conditional-formats, or the cells' style:map where a table has none. ConditionalFormats::read(table) and style_for(sheet, row, column, value, cells) give the style of the first condition that holds.
  • Conditions supported: = != < > <= >=, between and not-between (inclusive), formula-is with references relative to base-cell-address (moved by formula::shifted), and begins-with, ends-with, contains-text and not-contains-text (case-insensitive). Any other condition never matches.
  • The applied styles are worked out when the sheet index is built: on open, after each edit and after each recalculation, never per frame. A document with no mapped cell styles skips the walk.
  • SheetDocument::shown_style lays the applied style over cell_style. The grid, the column fit and the PDF draw with it. Format cells and the mark keys keep reading the cell's own style.
  • Fixture corpus/libreoffice/conditional.ods was written by LibreOffice, which saves both forms.

style_for takes the workbook's cells as well, since formula conditions read them.

@anderix

anderix commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Review fixes are in the second commit.

I measured LibreOffice's comparison rules before changing them. I built a probe sheet and exported it to HTML through LibreOffice, then read the cell colours. Results:

  • An empty cell is 0 against a number: it is red under <50, green under between(0,1) and green under !=5.
  • An empty cell is "" against text: it is red under ="".
  • Text against a number satisfies !=.
  • =0.3 matches 0.1+0.2.

Critical

  • 1: addresses are split at spaces outside quotes (new refs::split_addresses) and read with refs::read_area. That covers 'My Sheet'.A1 and a quoted :. (a_sheet_name_with_a_space_keeps_its_whole_range fails with the old split.)

Important

  • 2: a range is worked out to its own edges, past the used cells, unless it covers more than 100,000 cells (cells_past_the_last_used_one_are_styled_too).
  • 3: text against a number satisfies != (text_is_not_equal_to_a_number).
  • 4:
    • The applied styles live in a OnceCell per sheet. Building the index no longer computes them; the first lookup after a rebuild does, once, so pasting N cells costs one computation.
    • An expression without relative references is parsed once.
    • A relative formula condition is still parsed per cell, since Reference carries no relative flags to shift a parsed tree by. Changing that is a formula-engine change outside this task.

Minors

  • 5: fixed to LibreOffice's rule as measured (an_empty_cell_is_nought_or_no_text).
  • 6: column_index saturates, and ranges past XFD1048576 are dropped (a_column_too_long_to_count_is_no_range).
  • 7: = is approximate (equal_allows_for_rounding).
  • 8: document_is_unchanged_after_open compares against a Document that never went through SheetDocument.

Left alone: refs::rename_in_addresses's space split is pre-existing and outside this PR.

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.

xods: draw conditional formatting

1 participant