vimsheet.model.sheet

Sheet model — a single tab in a workbook.

class vimsheet.model.sheet.CondFormatRule(range_str, operator, value, value2=None, fmt=<factory>)[source]

Bases: object

A conditional formatting rule applied to a range.

Parameters:
range_str: str
operator: str
value: Any
value2: Any = None
fmt: CellFormat
matches(cell_value)[source]

Return True if cell_value satisfies this rule’s condition.

Parameters:

cell_value (Any)

Return type:

bool

__init__(range_str, operator, value, value2=None, fmt=<factory>)
Parameters:
Return type:

None

class vimsheet.model.sheet.FilterRule(operator, value)[source]

Bases: object

A column filter rule.

Parameters:
operator: str
value: Any
matches(cell_value)[source]

Return True if cell_value satisfies this filter.

Parameters:

cell_value (Any)

Return type:

bool

__init__(operator, value)
Parameters:
Return type:

None

class vimsheet.model.sheet.SortState(sort_keys)[source]

Bases: object

Remembered sort configuration for a sheet.

Parameters:

sort_keys (list[tuple[int, bool]])

sort_keys: list[tuple[int, bool]]
__init__(sort_keys)
Parameters:

sort_keys (list[tuple[int, bool]])

Return type:

None

class vimsheet.model.sheet.Sheet(name, cells=<factory>, col_widths=<factory>, row_heights=<factory>, hidden_rows=<factory>, hidden_cols=<factory>, row_groups=<factory>, col_groups=<factory>, freeze_rows=0, freeze_cols=0, named_ranges=<factory>, cond_formats=<factory>, filters=<factory>, sort_state=None, max_row=0, max_col=0, validation=<factory>, cursor_row=0, cursor_col=0)[source]

Bases: object

A single sheet (tab) inside a workbook.

Parameters:
name: str
cells: dict[tuple[int, int], Cell]
col_widths: dict[int, int]
row_heights: dict[int, int]
hidden_rows: set[int]
hidden_cols: set[int]
row_groups: list[tuple[int, int]]
col_groups: list[tuple[int, int]]
freeze_rows: int = 0
freeze_cols: int = 0
named_ranges: NamedRangeRegistry
cond_formats: list[CondFormatRule]
filters: dict[int, FilterRule]
sort_state: SortState | None = None
max_row: int = 0
max_col: int = 0
validation: SheetValidation
cursor_row: int = 0
cursor_col: int = 0
autocalc: bool = True
get_cell(row, col)[source]

Return the Cell at (row, col), or None if the cell is empty.

Parameters:
Return type:

Cell | None

cell(address)[source]

Return the cell at an A1-notation address, or None.

Parameters:

address (str)

Return type:

Cell | None

set_cell_value(row, col, value, formula=None, record_history=True)[source]

Set a cell’s value (and optional formula); create the cell if absent.

Parameters:
Return type:

Cell

clear_cell(row, col)[source]

Remove all content from a cell.

Parameters:
Return type:

None

set_cells_batch(updates)[source]

Set plain values for many cells in one pass, recalculating only once.

Parameters:

updates (list[tuple[int, int, Any]])

Return type:

None

clear_cells_batch(positions)[source]

Remove content from many cells in one pass, recalculating only once.

Parameters:

positions (list[tuple[int, int]])

Return type:

None

get_range_values(cell_range)[source]

Return a 2-D list of values for the given range.

Parameters:

cell_range (CellRange)

Return type:

list[list[Any]]

insert_row(before_row)[source]

Insert a blank row before before_row, shifting cells down.

Parameters:

before_row (int)

Return type:

None

delete_row(row)[source]

Delete row, shift cells up. Returns snapshot of deleted cells keyed by col.

Parameters:

row (int)

Return type:

dict[int, Cell]

insert_col(before_col)[source]

Insert a blank column before before_col, shifting cells right.

Parameters:

before_col (int)

Return type:

None

delete_col(col)[source]

Delete col, shift cells left. Returns snapshot keyed by row.

Parameters:

col (int)

Return type:

dict[int, Cell]

DEFAULT_COL_WIDTH = 10
get_col_width(col)[source]

Return column width in characters.

Parameters:

col (int)

Return type:

int

set_col_width(col, width)[source]

Set column width, clamped to [2, 80].

Parameters:
Return type:

None

auto_fit_col(col)[source]

Set column width to the longest content in that column.

Parameters:

col (int)

Return type:

None

used_range()[source]

Return the bounding CellRange of all non-empty cells, or None.

Return type:

CellRange | None

sort_by_col(col, ascending=True)[source]

Sort all rows by col (0-based). Single-key convenience.

Parameters:
Return type:

None

sort_by_cols(sort_keys)[source]

Sort cells in each specified column independently. Other columns unchanged.

Parameters:

sort_keys (list[tuple[int, bool]])

Return type:

None

sort_range_columns(r1, c1, r2, c2, sort_keys)[source]

Sort each column within (r1,c1)-(r2,c2) independently. sort_keys is (col, ascending) pairs.

Parameters:
Return type:

None

apply_filters()[source]

Update hidden_rows based on the current filter rules.

Return type:

None

__init__(name, cells=<factory>, col_widths=<factory>, row_heights=<factory>, hidden_rows=<factory>, hidden_cols=<factory>, row_groups=<factory>, col_groups=<factory>, freeze_rows=0, freeze_cols=0, named_ranges=<factory>, cond_formats=<factory>, filters=<factory>, sort_state=None, max_row=0, max_col=0, validation=<factory>, cursor_row=0, cursor_col=0)
Parameters:
Return type:

None