# Workbook model

`load_workbook` and the openpyxl-like objects it returns.

[API reference](<https://justybase.github.io/xlspy/api/index.md>) · [Guide](<https://justybase.github.io/xlspy/usage/index.md>)

## load\_workbook

```
load_workbook(filename: str | PathLike[str] | IO[bytes], *, read_only: bool = False, data_only: bool = False, keep_vba: bool = False, rich_text: bool = False, keep_links: bool = True) -> Workbook
```

Load an XLSX/XLSM workbook, or stream an XLSB/XLSX with `read_only`.

The fast `ExcelReader` remains the best choice for raw value extraction. This function adds coordinates, styles, merges, dimensions and editing.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `filename` | `str \| PathLike[str] \| IO[bytes]` | Path to an `.xlsx`, `.xlsm` or `.xlsb` file, a `scheme://` URI opened through fsspec, or a binary file object such as `io.BytesIO`. The object is not closed. | *required* |
| `read_only` | `bool` | Stream rows instead of building the full model. Read-only sheets cannot be edited or saved. | `False` |
| `data_only` | `bool` | Return cached formula results instead of formula text. | `False` |
| `keep_vba` | `bool` | Keep the VBA project of an `.xlsm` workbook. | `False` |
| `rich_text` | `bool` | Preserve rich-text runs as `CellRichText` values. | `False` |
| `keep_links` | `bool` | Keep external workbook links in the model. | `True` |

Examples:

Read a value, edit it and save a copy:

```
from xlspy import load_workbook

workbook = load_workbook("report.xlsx")
sheet = workbook["Sales"]
print(sheet["A1"].value)
sheet["B2"] = 130
workbook.save("report-updated.xlsx")
workbook.close()
```

Stream a large sheet without loading it whole:

```
workbook = load_workbook("large.xlsb", read_only=True)
for row in workbook["Data"].iter_rows(min_row=1, max_row=5, values_only=True):
    print(row)
workbook.close()
```

**See Also**

`ExcelReader` for the fastest values-only path, and `Workbook` for the in-memory model this function returns.

## Workbook

```
Workbook(write_only: bool = False, iso_dates: bool = False)
```

An Excel workbook in memory, with openpyxl's interface.

`Workbook()` starts with one empty sheet; `load_workbook` opens a file. `save` writes a new workbook as XLSB or XLSX/XLSM by the file extension, and a loaded workbook in the format it was loaded from.

Examples:

Build a workbook cell by cell, like openpyxl:

```
from xlspy import Workbook

workbook = Workbook()
sheet = workbook.active
sheet.title = "Data"
sheet["A1"] = "Item"
sheet["A2"] = 1200
workbook.save("book.xlsx")
workbook.close()
```

`save` chooses the format from the extension, so `"book.xlsb"` writes a binary XLSB package from the same code.

**See Also**

`load_workbook` to open an existing file, and `XlsxWriter` / `XlsbWriter` for the faster row-oriented API.

### sheetnames

```
sheetnames: list[str]
```

The worksheet names, in order.

Chartsheets are kept in `chartsheets` and are not listed here. This is deliberate: openpyxl's `sheetnames` includes chartsheets, so code that needs them must read `chartsheets`.

### read\_only

```
read_only: bool
```

True for a workbook loaded with `read_only=True`, which cannot be saved.

### data\_only

```
data_only: bool
```

True when the workbook was loaded with `data_only=True`.

### excel\_base\_date

```
excel_base_date: datetime
```

The base date of serial date numbers, as openpyxl names `epoch`.

### path

```
path: str
```

The workbook part name.

### mime\_type

```
mime_type: str
```

The content type the workbook's extension stands for.

### style\_names

```
style_names: list[str]
```

The names of the workbook's named styles, as openpyxl lists them.

### worksheets

```
worksheets: list[Worksheet]
```

The worksheets, in order (a new list).

### chartsheets

```
chartsheets: list[Chartsheet]
```

The chartsheets, in order (a new list).

### active

```
active: Worksheet
```

The active worksheet; set it with a worksheet or its index.

### properties

```
properties: DocumentProperties
```

The document properties: title, author, dates and so on.

### defined\_names

```
defined_names: DefinedNameList
```

The workbook's defined names.

### add\_vba\_project

```
add_vba_project(project: Any) -> None
```

Embed a VBA project (`vbaProject.bin`) in a new macro-enabled workbook.

`project` may be a path, bytes or a binary file object. Save the workbook as `.xlsm` or `.xltm`; another extension is refused rather than dropping the project silently.

### set\_vba\_name

```
set_vba_name(name: str) -> None
```

Set the VBA project's code name (`workbookPr/@codeName`).

### get\_sheet\_by\_name

```
get_sheet_by_name(name: str) -> Worksheet
```

Return the worksheet called `name`; the same as `wb[name]`.

### get\_sheet\_names

```
get_sheet_names() -> list[str]
```

The worksheet names, as openpyxl's deprecated alias for `sheetnames`.

### get\_index

```
get_index(worksheet: Worksheet | str) -> int
```

Return the 0-based position of `worksheet` or its title, as openpyxl's alias for `index`.

### index

```
index(worksheet: Worksheet | str) -> int
```

Return the 0-based position of `worksheet`, or of a sheet title.

### create\_sheet

```
create_sheet(title: str | None = None, index: int | None = None) -> Worksheet
```

Add a worksheet and return it.

Without a title it is named like openpyxl names it: `"Sheet"`, then `"Sheet1"`, `"Sheet2"` and so on, skipping a name already taken. Without an index it is added last.

### create\_chartsheet

```
create_chartsheet(title: str | None = None, index: int | None = None) -> Chartsheet
```

Add a chartsheet after the other sheets (XLSX only), as openpyxl does.

### move\_sheet

```
move_sheet(sheet: Worksheet | str, offset: int = 0) -> None
```

Move a sheet `offset` positions (negative: towards the front), as openpyxl does.

### remove

```
remove(worksheet: Worksheet) -> None
```

Remove `worksheet` from the workbook.

### remove\_sheet

```
remove_sheet(worksheet: Worksheet) -> None
```

Remove `worksheet`, as openpyxl's deprecated alias for `remove`.

### copy\_worksheet

```
copy_worksheet(from_worksheet: Worksheet) -> Worksheet
```

Copy a worksheet to a new sheet named after it, and return the copy.

Cells with their styles, notes and links, merged ranges, row and column sizes, the view, filter and page settings are copied. Charts, images, tables, data validations and conditional formats are not.

### add\_named\_style

```
add_named_style(style: NamedStyle) -> None
```

Register a NamedStyle so that cells can use it by name.

### create\_named\_range

```
create_named_range(name: str, worksheet: Worksheet | None = None, value: str | None = None, scope: str | None = None) -> None
```

Add a defined name, as openpyxl's deprecated `create_named_range`.

Prefer `workbook.defined_names[name] = DefinedName(...)`.

### save

```
save(filename: WriteTarget) -> None
```

Write the workbook to `filename`, a path, a `scheme://` URI or a writable binary file.

A URI is uploaded through fsspec; the extension of its path chooses the format. Raises ValueError for a workbook loaded with `read_only=True`.

### close

```
close() -> None
```

Release the files held by a loaded or read-only workbook.

## Worksheet

```
Worksheet(workbook: Workbook, title: str, *, index: int | None = None)
```

A worksheet of a `Workbook`, with openpyxl's interface.

Get one from `wb.active`, `wb["Name"]` or `Workbook.create_sheet`. Address cells with `ws["A1"]`, `ws["A1:C3"]` or `cell`; add rows with `append`.

### parent

```
parent: Workbook
```

The workbook that holds the sheet, as openpyxl names it.

### encoding

```
encoding: str
```

Always `"utf-8"`, for openpyxl compatibility.

### mime\_type

```
mime_type: str
```

The content type of a worksheet part.

### path

```
path: str
```

The worksheet part name, such as `/xl/worksheets/sheet1.xml`.

### title

```
title: str
```

The sheet name.

Setting it renames the sheet and points formulas, validations, conditional formats, internal links and defined names at the new name, as Excel does.

### sheet\_state

```
sheet_state: str
```

`"visible"`, `"hidden"` or `"veryHidden"`.

### merged\_cells

```
merged_cells: MultiCellRange
```

The merged ranges of the sheet.

### merged\_cell\_ranges

```
merged_cell_ranges: list[str]
```

A copy of the merged range strings, as openpyxl's deprecated alias.

### array\_formulae

```
array_formulae: dict[str, str]
```

Array formula anchors and the range each one fills, as openpyxl maps them.

### column\_groups

```
column_groups: list[str]
```

The column ranges that span more than one column, such as `"A:C"`.

### column\_dimensions

```
column_dimensions: DimensionHolder
```

Column widths, visibility and outline levels, keyed by column letter.

Looking up a column that has no entry creates one.

### row\_dimensions

```
row_dimensions: DimensionHolder
```

Row heights, visibility and outline levels, keyed by 1-based row number.

Looking up a row that has no entry creates one.

### freeze\_panes

```
freeze_panes: str | None
```

The top-left cell of the scrolling pane, or None.

`"B2"` freezes row 1 and column A. Read from `sheet_view.pane`, as openpyxl does, so a pane set through the view is visible here.

### auto\_filter

```
auto_filter: AutoFilter
```

The sheet's AutoFilter: its range, filter columns and sort state.

### sheet\_properties

```
sheet_properties: SheetProperties
```

Sheet properties such as the tab colour and outline settings.

### sheet\_view

```
sheet_view: SheetView
```

The first sheet view: zoom, grid lines, selection and panes.

### views

```
views: SheetViewList
```

Every sheet view, as openpyxl's `ws.views`.

### defined\_names

```
defined_names: MutableMapping[str, Any]
```

The defined names scoped to this sheet, keyed by name, as openpyxl's map.

Assigning an entry stores it on the workbook with this sheet as its scope, so it is written on save. Deleting one removes only this sheet's entry.

### scenarios

```
scenarios: Any
```

The sheet's scenarios: always None, because xlspy preserves but does not model them.

openpyxl reports an empty `ScenarioList` on a sheet without scenarios.

### legacy\_drawing

```
legacy_drawing: str | None
```

The relationship id of the sheet's legacy VML drawing.

Always None: the loaders preserve the part but do not expose its id, so this is a placeholder for openpyxl's attribute.

### active\_cell

```
active_cell: str | None
```

The active cell of the first selection, or None when the view has none.

### selected\_cell

```
selected_cell: str | None
```

The selected range of the first selection, or None when the view has none.

### show\_gridlines

```
show_gridlines: bool | None
```

Whether the sheet view shows grid lines; None leaves Excel's default.

### protection

```
protection: WorksheetProtection
```

Sheet protection settings.

### page\_margins

```
page_margins: WorksheetPageMargins
```

Page margins for printing, in inches.

### max\_row

```
max_row: int
```

The last row that holds a cell; 0 for an empty sheet.

### max\_column

```
max_column: int
```

The last column that holds a cell; 0 for an empty sheet.

### min\_row

```
min_row: int
```

Always 1: the used range is reported from A1, as openpyxl does for new sheets.

### min\_column

```
min_column: int
```

Always 1: the used range is reported from A1, as openpyxl does for new sheets.

### dimensions

```
dimensions: str
```

The used range from A1, such as `"A1:D20"`; `"A1:A1"` for an empty sheet.

### rows

```
rows: Iterator[tuple[Cell, ...]]
```

The rows of the used range as tuples of cells (see `iter_rows`).

### columns

```
columns: Iterator[tuple[Cell, ...]]
```

The columns of the used range as tuples of cells (see `iter_cols`).

### values

```
values: Iterator[tuple[Any, ...]]
```

The rows of the used range as tuples of values.

### data\_validations

```
data_validations: DataValidationList
```

The sheet's data validation rules.

### tables

```
tables: TableList
```

The sheet's tables; a table name also works as a lookup key.

### charts

```
charts: list[Chart]
```

The charts on the sheet, new and loaded.

### images

```
images: list[Image]
```

The images on the sheet.

### conditional\_formatting

```
conditional_formatting: ConditionalFormattingList
```

The sheet's conditional formatting, grouped by range.

### oddHeader

```
oddHeader: HeaderFooterItem
```

The header of odd pages (all pages unless odd and even pages differ).

### oddFooter

```
oddFooter: HeaderFooterItem
```

The footer of odd pages (all pages unless odd and even pages differ).

### evenHeader

```
evenHeader: HeaderFooterItem
```

The header of even pages, when odd and even pages differ.

### evenFooter

```
evenFooter: HeaderFooterItem
```

The footer of even pages, when odd and even pages differ.

### firstHeader

```
firstHeader: HeaderFooterItem
```

The header of the first page, when the first page differs.

### firstFooter

```
firstFooter: HeaderFooterItem
```

The footer of the first page, when the first page differs.

### print\_area

```
print_area: str | None
```

The print area as a range string, or None.

### print\_title\_rows

```
print_title_rows: str | None
```

Rows repeated at the top of every printed page, such as `"1:2"`.

### print\_title\_cols

```
print_title_cols: str | None
```

Columns repeated at the left of every printed page, such as `"A:B"`.

### print\_titles

```
print_titles: str
```

The print titles as openpyxl formats them, e.g. `'Sheet'!$1:$2`.

### calculate\_dimension

```
calculate_dimension(force: bool = False) -> str
```

Return `dimensions`. `force` is accepted for openpyxl compatibility.

### insert\_rows

```
insert_rows(idx: int, amount: int = 1) -> None
```

Insert `amount` empty rows before row `idx`.

### delete\_rows

```
delete_rows(idx: int, amount: int = 1) -> None
```

Delete `amount` rows starting at row `idx`; the rows below move up.

### insert\_cols

```
insert_cols(idx: int, amount: int = 1) -> None
```

Insert `amount` empty columns before column `idx` (1-based).

### delete\_cols

```
delete_cols(idx: int, amount: int = 1) -> None
```

Delete `amount` columns starting at column `idx`; the rest move left.

### move\_range

```
move_range(cell_range: str, rows: int = 0, cols: int = 0, translate: bool = False) -> None
```

Move the cells of `cell_range`; cells at the destination are replaced. `translate=True` shifts the relative references of moved formulas.

### add\_chart

```
add_chart(chart: Chart, anchor: str | None = None) -> None
```

Place `chart` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_image

```
add_image(img: Image, anchor: str | None = None) -> None
```

Place `img` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_table

```
add_table(table: ExcelTable | Table) -> None
```

Add a table: an `ExcelTable` or an openpyxl-style `Table`.

### add\_data\_validation

```
add_data_validation(data_validation: DataValidation) -> None
```

Add a data validation rule.

### cell

```
cell(row: int, column: int | str, value: Any = None) -> Cell
```

Return the cell at `row` and `column`, creating it when needed.

Both are 1-based; the column may also be a letter. A `value` other than None is assigned to the cell. A cell inside a merged range, other than its top-left one, is a read-only `MergedCell`.

### append

```
append(iterable: Iterable[Any]) -> int
```

Write a row after the last used row and return its row number.

`iterable` holds the values from column A on; a mapping places its values by column letter or 1-based column number instead.

### iter\_rows

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | None = None, max_col: int | None = None, values_only: Literal[False] = False) -> Iterator[tuple[Cell, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | None = None, max_col: int | None = None, *, values_only: Literal[True]) -> Iterator[tuple[Any, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | None = None, max_col: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | None = None, max_col: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

Yield the rows of a range as tuples of cells, or of values with `values_only`.

Bounds are 1-based and inclusive; each one left out defaults to the used range.

### iter\_cols

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: Literal[False] = False) -> Iterator[tuple[Cell, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, *, values_only: Literal[True]) -> Iterator[tuple[Any, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

Yield the columns of a range as tuples of cells, or of values with `values_only`.

Bounds are 1-based and inclusive; each one left out defaults to the used range.

### merge\_cells

```
merge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Merge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

### unmerge\_cells

```
unmerge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Unmerge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

## ReadOnlyWorksheet

```
ReadOnlyWorksheet(workbook: Workbook, title: str, *, reader: ExcelReader, data_only: bool, index: int | None = None)
```

Bases: `Worksheet`

Streams rows on demand with openpyxl's read-only semantics.

Rows and columns use worksheet coordinates: rows missing from the file are yielded as empty rows and columns start at `min_col` (default 1). Bounds come from the stored dimension; without one, `max_row` and `max_column` are None and rows are as wide as their last cell.

### min\_row

```
min_row: int
```

The first row of the sheet's dimension.

### min\_column

```
min_column: int
```

The first column of the sheet's dimension.

### max\_row

```
max_row: int | None
```

The last row of the dimension stored in the file, or None when it stores none.

See `calculate_dimension`.

### max\_column

```
max_column: int | None
```

The last column of the dimension stored in the file, or None when it stores none.

See `calculate_dimension`.

### dimensions

```
dimensions: str
```

The used range; raises ValueError when the file stores no dimension.

### page\_margins

```
page_margins: WorksheetPageMargins
```

Page margins for printing, in inches.

### protection

```
protection: WorksheetProtection
```

Sheet protection settings.

### parent

```
parent: Workbook
```

The workbook that holds the sheet, as openpyxl names it.

### encoding

```
encoding: str
```

Always `"utf-8"`, for openpyxl compatibility.

### mime\_type

```
mime_type: str
```

The content type of a worksheet part.

### path

```
path: str
```

The worksheet part name, such as `/xl/worksheets/sheet1.xml`.

### title

```
title: str
```

The sheet name.

Setting it renames the sheet and points formulas, validations, conditional formats, internal links and defined names at the new name, as Excel does.

### sheet\_state

```
sheet_state: str
```

`"visible"`, `"hidden"` or `"veryHidden"`.

### merged\_cells

```
merged_cells: MultiCellRange
```

The merged ranges of the sheet.

### merged\_cell\_ranges

```
merged_cell_ranges: list[str]
```

A copy of the merged range strings, as openpyxl's deprecated alias.

### array\_formulae

```
array_formulae: dict[str, str]
```

Array formula anchors and the range each one fills, as openpyxl maps them.

### column\_groups

```
column_groups: list[str]
```

The column ranges that span more than one column, such as `"A:C"`.

### column\_dimensions

```
column_dimensions: DimensionHolder
```

Column widths, visibility and outline levels, keyed by column letter.

Looking up a column that has no entry creates one.

### row\_dimensions

```
row_dimensions: DimensionHolder
```

Row heights, visibility and outline levels, keyed by 1-based row number.

Looking up a row that has no entry creates one.

### freeze\_panes

```
freeze_panes: str | None
```

The top-left cell of the scrolling pane, or None.

`"B2"` freezes row 1 and column A. Read from `sheet_view.pane`, as openpyxl does, so a pane set through the view is visible here.

### auto\_filter

```
auto_filter: AutoFilter
```

The sheet's AutoFilter: its range, filter columns and sort state.

### sheet\_properties

```
sheet_properties: SheetProperties
```

Sheet properties such as the tab colour and outline settings.

### sheet\_view

```
sheet_view: SheetView
```

The first sheet view: zoom, grid lines, selection and panes.

### views

```
views: SheetViewList
```

Every sheet view, as openpyxl's `ws.views`.

### defined\_names

```
defined_names: MutableMapping[str, Any]
```

The defined names scoped to this sheet, keyed by name, as openpyxl's map.

Assigning an entry stores it on the workbook with this sheet as its scope, so it is written on save. Deleting one removes only this sheet's entry.

### scenarios

```
scenarios: Any
```

The sheet's scenarios: always None, because xlspy preserves but does not model them.

openpyxl reports an empty `ScenarioList` on a sheet without scenarios.

### legacy\_drawing

```
legacy_drawing: str | None
```

The relationship id of the sheet's legacy VML drawing.

Always None: the loaders preserve the part but do not expose its id, so this is a placeholder for openpyxl's attribute.

### active\_cell

```
active_cell: str | None
```

The active cell of the first selection, or None when the view has none.

### selected\_cell

```
selected_cell: str | None
```

The selected range of the first selection, or None when the view has none.

### show\_gridlines

```
show_gridlines: bool | None
```

Whether the sheet view shows grid lines; None leaves Excel's default.

### rows

```
rows: Iterator[tuple[Cell, ...]]
```

The rows of the used range as tuples of cells (see `iter_rows`).

### columns

```
columns: Iterator[tuple[Cell, ...]]
```

The columns of the used range as tuples of cells (see `iter_cols`).

### values

```
values: Iterator[tuple[Any, ...]]
```

The rows of the used range as tuples of values.

### data\_validations

```
data_validations: DataValidationList
```

The sheet's data validation rules.

### tables

```
tables: TableList
```

The sheet's tables; a table name also works as a lookup key.

### charts

```
charts: list[Chart]
```

The charts on the sheet, new and loaded.

### images

```
images: list[Image]
```

The images on the sheet.

### conditional\_formatting

```
conditional_formatting: ConditionalFormattingList
```

The sheet's conditional formatting, grouped by range.

### oddHeader

```
oddHeader: HeaderFooterItem
```

The header of odd pages (all pages unless odd and even pages differ).

### oddFooter

```
oddFooter: HeaderFooterItem
```

The footer of odd pages (all pages unless odd and even pages differ).

### evenHeader

```
evenHeader: HeaderFooterItem
```

The header of even pages, when odd and even pages differ.

### evenFooter

```
evenFooter: HeaderFooterItem
```

The footer of even pages, when odd and even pages differ.

### firstHeader

```
firstHeader: HeaderFooterItem
```

The header of the first page, when the first page differs.

### firstFooter

```
firstFooter: HeaderFooterItem
```

The footer of the first page, when the first page differs.

### print\_area

```
print_area: str | None
```

The print area as a range string, or None.

### print\_title\_rows

```
print_title_rows: str | None
```

Rows repeated at the top of every printed page, such as `"1:2"`.

### print\_title\_cols

```
print_title_cols: str | None
```

Columns repeated at the left of every printed page, such as `"A:B"`.

### print\_titles

```
print_titles: str
```

The print titles as openpyxl formats them, e.g. `'Sheet'!$1:$2`.

### calculate\_dimension

```
calculate_dimension(force: bool = False) -> str
```

Return the used range.

A sheet whose file stores no dimension raises ValueError, unless `force=True` scans its rows to find the range.

### reset\_dimensions

```
reset_dimensions() -> None
```

Ignore a wrong stored dimension, as openpyxl's reset\_dimensions().

### iter\_rows

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | str | None = None, max_col: int | str | None = None, values_only: Literal[False] = False) -> Iterator[tuple[Any, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | str | None = None, max_col: int | str | None = None, *, values_only: Literal[True]) -> Iterator[tuple[Any, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | str | None = None, max_col: int | str | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

```
iter_rows(min_row: int | None = None, max_row: int | None = None, min_col: int | str | None = None, max_col: int | str | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

Stream the rows of a range as tuples of read-only cells, or of values with `values_only`.

Rows missing from the file come back empty.

### iter\_cols

```
iter_cols(*args: Any, **kwargs: Any) -> NoReturn
```

Not available in read-only mode: raises AttributeError.

### cell

```
cell(row: int, column: int | str, value: Any = None) -> ReadOnlyCell | EmptyCell
```

Return the read-only cell at `row` and `column`, or an empty cell.

Each call scans the sheet; use `iter_rows` to read many cells.

### append

```
append(iterable: Iterable[Any]) -> NoReturn
```

Not available: read-only worksheets cannot be modified.

### insert\_rows

```
insert_rows(idx: int, amount: int = 1) -> None
```

Insert `amount` empty rows before row `idx`.

### delete\_rows

```
delete_rows(idx: int, amount: int = 1) -> None
```

Delete `amount` rows starting at row `idx`; the rows below move up.

### insert\_cols

```
insert_cols(idx: int, amount: int = 1) -> None
```

Insert `amount` empty columns before column `idx` (1-based).

### delete\_cols

```
delete_cols(idx: int, amount: int = 1) -> None
```

Delete `amount` columns starting at column `idx`; the rest move left.

### move\_range

```
move_range(cell_range: str, rows: int = 0, cols: int = 0, translate: bool = False) -> None
```

Move the cells of `cell_range`; cells at the destination are replaced. `translate=True` shifts the relative references of moved formulas.

### add\_chart

```
add_chart(chart: Chart, anchor: str | None = None) -> None
```

Place `chart` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_image

```
add_image(img: Image, anchor: str | None = None) -> None
```

Place `img` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_table

```
add_table(table: ExcelTable | Table) -> None
```

Add a table: an `ExcelTable` or an openpyxl-style `Table`.

### add\_data\_validation

```
add_data_validation(data_validation: DataValidation) -> None
```

Add a data validation rule.

### merge\_cells

```
merge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Merge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

### unmerge\_cells

```
unmerge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Unmerge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

## WriteOnlyWorksheet

```
WriteOnlyWorksheet(workbook: Workbook, title: str, *, index: int | None = None)
```

Bases: `Worksheet`

Streaming-friendly sheet that stores rows rather than Cell objects.

### page\_margins

```
page_margins: WorksheetPageMargins
```

Page margins for printing, in inches.

### protection

```
protection: WorksheetProtection
```

Sheet protection settings.

### parent

```
parent: Workbook
```

The workbook that holds the sheet, as openpyxl names it.

### encoding

```
encoding: str
```

Always `"utf-8"`, for openpyxl compatibility.

### mime\_type

```
mime_type: str
```

The content type of a worksheet part.

### path

```
path: str
```

The worksheet part name, such as `/xl/worksheets/sheet1.xml`.

### title

```
title: str
```

The sheet name.

Setting it renames the sheet and points formulas, validations, conditional formats, internal links and defined names at the new name, as Excel does.

### sheet\_state

```
sheet_state: str
```

`"visible"`, `"hidden"` or `"veryHidden"`.

### merged\_cells

```
merged_cells: MultiCellRange
```

The merged ranges of the sheet.

### merged\_cell\_ranges

```
merged_cell_ranges: list[str]
```

A copy of the merged range strings, as openpyxl's deprecated alias.

### array\_formulae

```
array_formulae: dict[str, str]
```

Array formula anchors and the range each one fills, as openpyxl maps them.

### column\_groups

```
column_groups: list[str]
```

The column ranges that span more than one column, such as `"A:C"`.

### column\_dimensions

```
column_dimensions: DimensionHolder
```

Column widths, visibility and outline levels, keyed by column letter.

Looking up a column that has no entry creates one.

### row\_dimensions

```
row_dimensions: DimensionHolder
```

Row heights, visibility and outline levels, keyed by 1-based row number.

Looking up a row that has no entry creates one.

### freeze\_panes

```
freeze_panes: str | None
```

The top-left cell of the scrolling pane, or None.

`"B2"` freezes row 1 and column A. Read from `sheet_view.pane`, as openpyxl does, so a pane set through the view is visible here.

### auto\_filter

```
auto_filter: AutoFilter
```

The sheet's AutoFilter: its range, filter columns and sort state.

### sheet\_properties

```
sheet_properties: SheetProperties
```

Sheet properties such as the tab colour and outline settings.

### sheet\_view

```
sheet_view: SheetView
```

The first sheet view: zoom, grid lines, selection and panes.

### views

```
views: SheetViewList
```

Every sheet view, as openpyxl's `ws.views`.

### defined\_names

```
defined_names: MutableMapping[str, Any]
```

The defined names scoped to this sheet, keyed by name, as openpyxl's map.

Assigning an entry stores it on the workbook with this sheet as its scope, so it is written on save. Deleting one removes only this sheet's entry.

### scenarios

```
scenarios: Any
```

The sheet's scenarios: always None, because xlspy preserves but does not model them.

openpyxl reports an empty `ScenarioList` on a sheet without scenarios.

### legacy\_drawing

```
legacy_drawing: str | None
```

The relationship id of the sheet's legacy VML drawing.

Always None: the loaders preserve the part but do not expose its id, so this is a placeholder for openpyxl's attribute.

### active\_cell

```
active_cell: str | None
```

The active cell of the first selection, or None when the view has none.

### selected\_cell

```
selected_cell: str | None
```

The selected range of the first selection, or None when the view has none.

### show\_gridlines

```
show_gridlines: bool | None
```

Whether the sheet view shows grid lines; None leaves Excel's default.

### max\_row

```
max_row: int
```

The last row that holds a cell; 0 for an empty sheet.

### max\_column

```
max_column: int
```

The last column that holds a cell; 0 for an empty sheet.

### min\_row

```
min_row: int
```

Always 1: the used range is reported from A1, as openpyxl does for new sheets.

### min\_column

```
min_column: int
```

Always 1: the used range is reported from A1, as openpyxl does for new sheets.

### dimensions

```
dimensions: str
```

The used range from A1, such as `"A1:D20"`; `"A1:A1"` for an empty sheet.

### rows

```
rows: Iterator[tuple[Cell, ...]]
```

The rows of the used range as tuples of cells (see `iter_rows`).

### columns

```
columns: Iterator[tuple[Cell, ...]]
```

The columns of the used range as tuples of cells (see `iter_cols`).

### values

```
values: Iterator[tuple[Any, ...]]
```

The rows of the used range as tuples of values.

### data\_validations

```
data_validations: DataValidationList
```

The sheet's data validation rules.

### tables

```
tables: TableList
```

The sheet's tables; a table name also works as a lookup key.

### charts

```
charts: list[Chart]
```

The charts on the sheet, new and loaded.

### images

```
images: list[Image]
```

The images on the sheet.

### conditional\_formatting

```
conditional_formatting: ConditionalFormattingList
```

The sheet's conditional formatting, grouped by range.

### oddHeader

```
oddHeader: HeaderFooterItem
```

The header of odd pages (all pages unless odd and even pages differ).

### oddFooter

```
oddFooter: HeaderFooterItem
```

The footer of odd pages (all pages unless odd and even pages differ).

### evenHeader

```
evenHeader: HeaderFooterItem
```

The header of even pages, when odd and even pages differ.

### evenFooter

```
evenFooter: HeaderFooterItem
```

The footer of even pages, when odd and even pages differ.

### firstHeader

```
firstHeader: HeaderFooterItem
```

The header of the first page, when the first page differs.

### firstFooter

```
firstFooter: HeaderFooterItem
```

The footer of the first page, when the first page differs.

### print\_area

```
print_area: str | None
```

The print area as a range string, or None.

### print\_title\_rows

```
print_title_rows: str | None
```

Rows repeated at the top of every printed page, such as `"1:2"`.

### print\_title\_cols

```
print_title_cols: str | None
```

Columns repeated at the left of every printed page, such as `"A:B"`.

### print\_titles

```
print_titles: str
```

The print titles as openpyxl formats them, e.g. `'Sheet'!$1:$2`.

### append

```
append(iterable: Iterable[Any]) -> int
```

Queue a row for writing and return its row number.

A mapping places its values by column letter or 1-based column number. A `WriteOnlyCell` contributes its value and, when it has one, its style; the writer then writes the cell with that style.

### cell

```
cell(row: int, column: int | str, value: Any = None) -> Cell
```

Not available in write-only mode: raises ValueError. Use `append`.

### iter\_rows

```
iter_rows(*args: Any, **kwargs: Any) -> Iterator[tuple[Any, ...]]
```

Yield the queued rows as tuples of values; only `values_only=True` is supported.

### calculate\_dimension

```
calculate_dimension(force: bool = False) -> str
```

Return `dimensions`. `force` is accepted for openpyxl compatibility.

### insert\_rows

```
insert_rows(idx: int, amount: int = 1) -> None
```

Insert `amount` empty rows before row `idx`.

### delete\_rows

```
delete_rows(idx: int, amount: int = 1) -> None
```

Delete `amount` rows starting at row `idx`; the rows below move up.

### insert\_cols

```
insert_cols(idx: int, amount: int = 1) -> None
```

Insert `amount` empty columns before column `idx` (1-based).

### delete\_cols

```
delete_cols(idx: int, amount: int = 1) -> None
```

Delete `amount` columns starting at column `idx`; the rest move left.

### move\_range

```
move_range(cell_range: str, rows: int = 0, cols: int = 0, translate: bool = False) -> None
```

Move the cells of `cell_range`; cells at the destination are replaced. `translate=True` shifts the relative references of moved formulas.

### add\_chart

```
add_chart(chart: Chart, anchor: str | None = None) -> None
```

Place `chart` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_image

```
add_image(img: Image, anchor: str | None = None) -> None
```

Place `img` on the sheet, at `anchor` (a cell such as `"E2"`) when given.

### add\_table

```
add_table(table: ExcelTable | Table) -> None
```

Add a table: an `ExcelTable` or an openpyxl-style `Table`.

### add\_data\_validation

```
add_data_validation(data_validation: DataValidation) -> None
```

Add a data validation rule.

### iter\_cols

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: Literal[False] = False) -> Iterator[tuple[Cell, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, *, values_only: Literal[True]) -> Iterator[tuple[Any, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

```
iter_cols(min_col: int | None = None, max_col: int | None = None, min_row: int | None = None, max_row: int | None = None, values_only: bool = False) -> Iterator[tuple[Any, ...]]
```

Yield the columns of a range as tuples of cells, or of values with `values_only`.

Bounds are 1-based and inclusive; each one left out defaults to the used range.

### merge\_cells

```
merge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Merge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

### unmerge\_cells

```
unmerge_cells(range_string: str | None = None, start_row: int | None = None, start_column: int | None = None, end_row: int | None = None, end_column: int | None = None) -> None
```

Unmerge a range, given as text such as `"A1:B2"` or as four 1-based boundaries.

## Chartsheet

```
Chartsheet(workbook: Workbook, title: str, index: int | None = None)
```

A chartsheet: a sheet that shows one chart.

A new chartsheet's chart reads its ranges from `source` (a worksheet or its title; by default the workbook's first worksheet).

### title

```
title: str
```

The sheet name. A loaded chartsheet cannot be renamed.

### charts

```
charts: list[Chart]
```

The chart of the sheet, as a list of at most one for a new chartsheet.

### add\_chart

```
add_chart(chart: Chart, source: Worksheet | str | None = None) -> None
```

Set the chart of a new chartsheet.

A chartsheet holds one chart; it reads its ranges from `source` (a worksheet or its title; by default the workbook's first worksheet).

## Cell

```
Cell(sheet: Worksheet, row: int, column: int, value: Any = None, style_id: int = 0)
```

One cell of a worksheet: its value, formula, style, note and hyperlink.

Get cells from the worksheet (`ws["A1"]`, `Worksheet.cell`); they are not created directly.

### row

```
row: int
```

The 1-based row number.

### column

```
column: int
```

The 1-based column number.

### column\_letter

```
column_letter: str
```

The column letter, such as `"C"`.

### col\_idx

```
col_idx: int
```

The 1-based column number, as openpyxl names it.

### coordinate

```
coordinate: str
```

The cell reference, such as `"C5"`.

### parent

```
parent: Worksheet
```

The worksheet that holds the cell.

### value

```
value: Any
```

The cell value; a scalar formula reads back as `"=..."` text.

An `ArrayFormula` or `DataTableFormula` reads back as that object, as in openpyxl. Assigning text that starts with `=` or a Formula sets a formula; an `ArrayFormula` or `DataTableFormula` sets that formula object, and a Hyperlink sets the link and shows its text; any other value keeps the cell's link, as in Excel (`hyperlink = None` removes it). A date, time or timedelta gets a default number format when the cell's format is `General`.

### formula

```
formula: Formula | ArrayFormula | DataTableFormula | str | None
```

The formula object or text without its leading `=`, or None.

### data\_type

```
data_type: str
```

openpyxl's type code: `n` number or empty, `s` text, `b` boolean, `d` date or time, `f` formula, `e` error.

### internal\_value

```
internal_value: Any
```

The stored value; None for a formula cell that holds no cached result.

### is\_date

```
is_date: bool
```

True when the value is a date, datetime, time or timedelta.

### encoding

```
encoding: str
```

Always `"utf-8"`, for openpyxl compatibility.

### base\_date

```
base_date: datetime
```

The workbook's `epoch`, the base date of serial date numbers (1899-12-30).

### hyperlink

```
hyperlink: Hyperlink | None
```

The cell's Hyperlink, or None.

### comment

```
comment: Comment | None
```

The cell's note (a Comment), or None.

### threaded\_comment

```
threaded_comment: ThreadedComment | None
```

The cell's Excel 365 conversation, or None.

Assigning a `ThreadedComment` starts a conversation; assigning None removes the whole conversation, replies included.

### style\_id

```
style_id: int
```

The index of the cell's style in the workbook's style table.

### has\_style

```
has_style: bool
```

True when the cell has a style other than the workbook default.

### font

```
font: Font | None
```

The cell font, or None when its style sets no font.

Assigning one replaces the font of the cell's style.

### fill

```
fill: str | PatternFill | GradientFill
```

The cell fill: a colour, a PatternFill or a GradientFill.

A cell without a fill reports openpyxl's empty pattern fill.

### border

```
border: Border
```

The cell border; a cell without one reports openpyxl's empty border.

### alignment

```
alignment: Alignment
```

The cell alignment; a cell without one reports openpyxl's default.

### protection

```
protection: Protection
```

The cell protection (locked, hidden).

A cell without explicit protection reports openpyxl's locked, visible default.

### quotePrefix

```
quotePrefix: bool
```

True when the cell's format sets Excel's quote prefix, as openpyxl's.

### pivotButton

```
pivotButton: bool
```

True when the cell's format sets Excel's pivot-button flag.

### number\_format

```
number_format: str
```

The number format code; `"General"` when none is set.

### style

```
style: Style
```

The cell's Style.

Assign a Style, or the name of a named style registered with `Workbook.add_named_style`.

### check\_error

```
check_error(value: Any) -> str
```

The text openpyxl stores for an error value: `str(value)` or `"#N/A"`.

### check\_string

```
check_string(value: Any) -> Any
```

The stored text for `value`, as openpyxl stores it.

Text is truncated to 32,767 characters and illegal control characters in what remains raise `IllegalCharacterError` with openpyxl's message. A non-string is decoded with the cell's UTF-8 encoding, as openpyxl decodes it.

### offset

```
offset(row: int = 0, column: int = 0) -> Cell
```

The cell `row` rows below and `column` columns right of this one.

Negative offsets go up and left.

## MergedCell

```
MergedCell(sheet: Worksheet, row: int, column: int, value: Any = None, style_id: int = 0)
```

Bases: `Cell`

A cell inside a merged range other than its top-left anchor.

### row

```
row: int
```

The 1-based row number.

### column

```
column: int
```

The 1-based column number.

### column\_letter

```
column_letter: str
```

The column letter, such as `"C"`.

### col\_idx

```
col_idx: int
```

The 1-based column number, as openpyxl names it.

### coordinate

```
coordinate: str
```

The cell reference, such as `"C5"`.

### parent

```
parent: Worksheet
```

The worksheet that holds the cell.

### formula

```
formula: Formula | ArrayFormula | DataTableFormula | str | None
```

The formula object or text without its leading `=`, or None.

### data\_type

```
data_type: str
```

openpyxl's type code: `n` number or empty, `s` text, `b` boolean, `d` date or time, `f` formula, `e` error.

### internal\_value

```
internal_value: Any
```

The stored value; None for a formula cell that holds no cached result.

### is\_date

```
is_date: bool
```

True when the value is a date, datetime, time or timedelta.

### encoding

```
encoding: str
```

Always `"utf-8"`, for openpyxl compatibility.

### base\_date

```
base_date: datetime
```

The workbook's `epoch`, the base date of serial date numbers (1899-12-30).

### hyperlink

```
hyperlink: Hyperlink | None
```

The cell's Hyperlink, or None.

### comment

```
comment: Comment | None
```

The cell's note (a Comment), or None.

### threaded\_comment

```
threaded_comment: ThreadedComment | None
```

The cell's Excel 365 conversation, or None.

Assigning a `ThreadedComment` starts a conversation; assigning None removes the whole conversation, replies included.

### style\_id

```
style_id: int
```

The index of the cell's style in the workbook's style table.

### has\_style

```
has_style: bool
```

True when the cell has a style other than the workbook default.

### font

```
font: Font | None
```

The cell font, or None when its style sets no font.

Assigning one replaces the font of the cell's style.

### fill

```
fill: str | PatternFill | GradientFill
```

The cell fill: a colour, a PatternFill or a GradientFill.

A cell without a fill reports openpyxl's empty pattern fill.

### border

```
border: Border
```

The cell border; a cell without one reports openpyxl's empty border.

### alignment

```
alignment: Alignment
```

The cell alignment; a cell without one reports openpyxl's default.

### protection

```
protection: Protection
```

The cell protection (locked, hidden).

A cell without explicit protection reports openpyxl's locked, visible default.

### quotePrefix

```
quotePrefix: bool
```

True when the cell's format sets Excel's quote prefix, as openpyxl's.

### pivotButton

```
pivotButton: bool
```

True when the cell's format sets Excel's pivot-button flag.

### number\_format

```
number_format: str
```

The number format code; `"General"` when none is set.

### style

```
style: Style
```

The cell's Style.

Assign a Style, or the name of a named style registered with `Workbook.add_named_style`.

### check\_error

```
check_error(value: Any) -> str
```

The text openpyxl stores for an error value: `str(value)` or `"#N/A"`.

### check\_string

```
check_string(value: Any) -> Any
```

The stored text for `value`, as openpyxl stores it.

Text is truncated to 32,767 characters and illegal control characters in what remains raise `IllegalCharacterError` with openpyxl's message. A non-string is decoded with the cell's UTF-8 encoding, as openpyxl decodes it.

### offset

```
offset(row: int = 0, column: int = 0) -> Cell
```

The cell `row` rows below and `column` columns right of this one.

Negative offsets go up and left.

## ReadOnlyCell

```
ReadOnlyCell(row: int, column: int, value: Any, number_format: str = 'General')
```

A cell value streamed from a read-only worksheet (as openpyxl's).

### coordinate

```
coordinate: str
```

The cell reference, such as `"C5"`.

### column\_letter

```
column_letter: str
```

The column letter, such as `"C"`.

### data\_type

```
data_type: str
```

openpyxl's type code for the value; `f` for formula text.

### is\_date

```
is_date: bool
```

True when the value is a date, datetime, time or timedelta.

## WriteOnlyCell

```
WriteOnlyCell(worksheet: Any, value: Any = None)
```

A value with optional style, used with `WriteOnlyWorksheet.append`.

## CellRange

Bases: `str`

An A1 range string with openpyxl-style boundary properties.

### min\_col

```
min_col: int
```

The first column, 1-based.

### min\_row

```
min_row: int
```

The first row, 1-based.

### max\_col

```
max_col: int
```

The last column, 1-based.

### max\_row

```
max_row: int
```

The last row, 1-based.

### coord

```
coord: str
```

The range as text, such as `"A1:C3"`.

### bounds

```
bounds: tuple[int, int, int, int]
```

`(min_col, min_row, max_col, max_row)`, 1-based.

### size

```
size: dict[str, int]
```

The size as `{"columns": n, "rows": m}`.

### shift

```
shift(col_shift: int = 0, row_shift: int = 0) -> CellRange
```

Return the range moved right by `col_shift` and down by `row_shift`.

Raises ValueError when the result leaves the worksheet.

### expand

```
expand(right: int = 0, down: int = 0, left: int = 0, up: int = 0) -> CellRange
```

Return the range grown by the given number of cells on each side.

Raises ValueError when the result leaves the worksheet.

### shrink

```
shrink(right: int = 0, bottom: int = 0, left: int = 0, top: int = 0) -> CellRange
```

Return the range made smaller by the given number of cells on each side.

### union

```
union(other: CellRange | str) -> CellRange
```

Return the smallest range that covers this range and `other`.

### intersection

```
intersection(other: CellRange | str) -> CellRange
```

Return the cells this range shares with `other`.

Raises ValueError when the ranges do not overlap.

### isdisjoint

```
isdisjoint(other: CellRange | str) -> bool
```

True when this range and `other` share no cell.

### issubset

```
issubset(other: CellRange | str) -> bool
```

True when every cell of this range is in `other`.

### issuperset

```
issuperset(other: CellRange | str) -> bool
```

True when every cell of `other` is in this range.

## MultiCellRange

```
MultiCellRange(ranges: Iterable[str] | None = None)
```

Several cell ranges, such as a sheet's merged cells, in the order added.

### ranges

```
ranges: list[CellRange]
```

The ranges in the order added. Code may change the list; the index follows it.

### add

```
add(value: str) -> None
```

Add a range unless it is already present.

### remove

```
remove(value: str) -> None
```

Remove a range; raises ValueError when it is not present.

### first\_overlapping

```
first_overlapping(bounds: tuple[int, int, int, int]) -> CellRange | None
```

The first range added that shares a cell with zero-based `bounds`, or None.

## Dimension

```
Dimension(index: str | int)
```

The size, visibility and outline settings of a row or column, with openpyxl's attribute names.

### customWidth

```
customWidth: bool
```

True when a width is set.

### customHeight

```
customHeight: bool
```

True when a height is set.

### outline\_level

```
outline_level: int
```

The outline (group) level; the same as `outlineLevel`.

## ColumnDimension

```
ColumnDimension(index: str | int)
```

Bases: `Dimension`

A column's width, visibility and outline level: `ws.column_dimensions["B"]`.

### range

```
range: str
```

The columns covered, such as `"A:C"`, as openpyxl names it.

### customWidth

```
customWidth: bool
```

True when a width is set.

### customHeight

```
customHeight: bool
```

True when a height is set.

### outline\_level

```
outline_level: int
```

The outline (group) level; the same as `outlineLevel`.

## RowDimension

```
RowDimension(index: str | int)
```

Bases: `Dimension`

A row's height, visibility and outline level: `ws.row_dimensions[3]`.

### customWidth

```
customWidth: bool
```

True when a width is set.

### customHeight

```
customHeight: bool
```

True when a height is set.

### outline\_level

```
outline_level: int
```

The outline (group) level; the same as `outlineLevel`.

## DimensionHolder

```
DimensionHolder(factory: Callable[[Any], Dimension], transform: Callable[[Any], Any])
```

Bases: `dict[Any, Any]`

### get

```
get(key: Any, default: Any = None) -> Any
```

Like `dict.get`, without creating an entry; the key may be a letter or a number.

### group

```
group(start: int | str, end: int | str | None = None, outline_level: int = 1, hidden: bool = False) -> None
```

Group consecutive rows or columns, as openpyxl does.

## Table

```
Table(id: int = 1, displayName: str | None = None, ref: str | None = None, name: str | None = None, comment: str | None = None, tableType: str | None = None, headerRowCount: int = 1, insertRow: bool | None = None, insertRowShift: bool | None = None, totalsRowCount: int | None = None, totalsRowShown: bool | None = None, published: bool | None = None, autoFilter: AutoFilter | None = None, sortState: SortState | None = None, tableColumns: Iterable[TableColumn] = (), tableStyleInfo: TableStyleInfo | None = None)
```

An openpyxl-style table: a named range with a header row, columns and a style.

Add it with `Worksheet.add_table`. `ExcelTable` is the equivalent for the writers.

### display\_name

```
display_name: str | None
```

The table name shown in Excel; the same as `displayName`.

### header\_row

```
header_row: bool
```

True when the table has a header row.

### totals\_row

```
totals_row: bool
```

True when the table has a totals row.

### columns

```
columns: list[str | None]
```

The column names.

### style\_name

```
style_name: str | None
```

The table style name, or None.

## TableColumn

```
TableColumn(id: int | None = None, name: str | None = None, totalsRowFunction: str | None = None, totalsRowLabel: str | None = None, calculatedColumnFormula: str | None = None, totalsRowFormula: str | None = None, xmlColumnPr: object = None)
```

A column of a `Table`: its name and totals row settings.

## TableStyleInfo

```
TableStyleInfo(name: str | None = None, showFirstColumn: bool | None = None, showLastColumn: bool | None = None, showRowStripes: bool | None = None, showColumnStripes: bool | None = None)
```

A table's style name and banding options.

## AutoFilter

```
AutoFilter(ref: str | None = None, filterColumn: list[FilterColumn] = list(), sortState: SortState | None = None)
```

### add\_filter\_column

```
add_filter_column(col_id: int, vals: Iterable[Any] | None, blank: bool = False) -> None
```

Filter column `col_id` (0-based within the filter range) to `vals`.

`blank=True` also shows blank cells.

### add\_sort\_condition

```
add_sort_condition(ref: str, descending: bool = False) -> None
```

Sort by the cells of `ref`, descending when asked.

## DefinedNameList

```
DefinedNameList(workbook: Workbook | None = None, definitions: Iterable[DefinedName] | None = None)
```

A list/dict hybrid of `DefinedName` entries.

### names

```
names: list[str]
```

The defined names, in order.

### keys

```
keys() -> list[str]
```

The defined names' names, as a dict-like view over the list.

### values

```
values() -> list[DefinedName]
```

The defined names, as a dict-like view over the list.

### items

```
items() -> list[tuple[str, DefinedName]]
```

The names and their definitions, as a dict-like view over the list.

### get

```
get(name: str, default: object = None) -> object
```

The definition called `name`, or `default` when there is none.

### add

```
add(definition: DefinedName, *, stage: bool = True) -> None
```

Add a defined name, replacing one with the same name and scope.

### remove

```
remove(name: str, scope: str | None = None) -> DefinedName
```

Remove a defined name and return it.

Without `scope` the first entry with the name goes. Raises KeyError when absent.

## DocumentProperties

```
DocumentProperties(creator: str = 'xlspy', title: str | None = None, subject: str | None = None, description: str | None = None, keywords: str | None = None, category: str | None = None, lastModifiedBy: str | None = None, created: datetime = now(), modified: datetime = now(), revision: str | None = None, contentStatus: str | None = None, identifier: str | None = None, language: str | None = None, version: str | None = None, lastPrinted: datetime | None = None)
```

## CustomProperty

```
CustomProperty(name: str, value: object)
```

## CustomPropertyList

Bases: `list`

A list of custom document properties, keyed by `name` for convenience.

### names

```
names: list[str]
```

The property names.

## CalcProperties

```
CalcProperties(calcId: int = 124519, calcMode: str | None = None, fullCalcOnLoad: bool = True, refMode: str | None = None, iterate: bool | None = None, iterateCount: int | None = None, iterateDelta: float | None = None, fullPrecision: bool | None = None, calcCompleted: bool | None = None, calcOnSave: bool | None = None, concurrentCalc: bool | None = None, concurrentManualCount: int | None = None, forceFullCalc: bool | None = None)
```

## BookView

```
BookView(visibility: str = 'visible', minimized: bool = False, showHorizontalScroll: bool = True, showVerticalScroll: bool = True, showSheetTabs: bool = True, xWindow: int | None = None, yWindow: int | None = None, windowWidth: int | None = None, windowHeight: int | None = None, tabRatio: int = 600, firstSheet: int = 0, activeTab: int = 0, autoFilterDateGrouping: bool = True)
```

## WorkbookSecurity

```
WorkbookSecurity(workbookPassword: str | None = None, workbookPasswordCharacterSet: str | None = None, revisionsPassword: str | None = None, revisionsPasswordCharacterSet: str | None = None, lockStructure: bool | None = None, lockWindows: bool | None = None, lockRevision: bool | None = None, revisionsAlgorithmName: str | None = None, revisionsHashValue: str | None = None, revisionsSaltValue: str | None = None, revisionsSpinCount: int | None = None, workbookAlgorithmName: str | None = None, workbookHashValue: str | None = None, workbookSaltValue: str | None = None, workbookSpinCount: int | None = None)
```

## SheetProperties

```
SheetProperties(tabColor: Color | str | None = None, codeName: str | None = None, pageSetUpPr: PageSetupProperties = PageSetupProperties(), outlinePr: Outline = Outline(), enableFormatConditionsCalculation: bool | None = None, filterMode: bool | None = None, published: bool | None = None, syncHorizontal: bool | None = None, syncRef: str | None = None, syncVertical: bool | None = None, transitionEvaluation: bool | None = None, transitionEntry: bool | None = None)
```

## SheetFormatProperties

```
SheetFormatProperties(baseColWidth: int = 8, defaultColWidth: float | None = None, defaultRowHeight: float = 15, customHeight: bool | None = None, zeroHeight: bool | None = None, thickTop: bool | None = None, thickBottom: bool | None = None, outlineLevelRow: int | None = None, outlineLevelCol: int | None = None)
```

## SheetView

```
SheetView(windowProtection: bool | None = None, showFormulas: bool | None = None, showGridLines: bool | None = None, showRowColHeaders: bool | None = None, showZeros: bool | None = None, rightToLeft: bool | None = None, tabSelected: bool | None = None, showRuler: bool | None = None, showOutlineSymbols: bool | None = None, defaultGridColor: bool | None = None, showWhiteSpace: bool | None = None, view: str | None = None, topLeftCell: str | None = None, colorId: int | None = None, zoomScale: int | None = None, zoomScaleNormal: int | None = None, zoomScaleSheetLayoutView: int | None = None, zoomScalePageLayoutView: int | None = None, zoomToFit: bool | None = None, workbookViewId: int = 0, selection: list[Selection] = list(), pane: Pane | None = None)
```

## Pane

```
Pane(xSplit: float | int | None = None, ySplit: float | int | None = None, topLeftCell: str | None = None, activePane: str = 'topLeft', state: str = 'split')
```

## Selection

```
Selection(pane: str | None = None, activeCell: str = 'A1', activeCellId: int | None = None, sqref: str = 'A1')
```

## Outline

```
Outline(applyStyles: bool | None = None, summaryBelow: bool | None = None, summaryRight: bool | None = None, showOutlineSymbols: bool | None = None)
```

## WorksheetProtection

```
WorksheetProtection(sheet: bool = False, objects: bool = False, scenarios: bool = False, formatCells: bool = True, formatRows: bool = True, formatColumns: bool = True, insertColumns: bool = True, insertRows: bool = True, insertHyperlinks: bool = True, deleteColumns: bool = True, deleteRows: bool = True, selectLockedCells: bool = False, selectUnlockedCells: bool = False, sort: bool = True, autoFilter: bool = True, pivotTables: bool = True, password: str | None = None, algorithmName: str | None = None, saltValue: str | None = None, spinCount: int | None = None, hashValue: str | None = None)
```

### set\_password

```
set_password(value: str | None = '', already_hashed: bool = False) -> None
```

Set the password, stored as its legacy hash unless `already_hashed`.

### enable

```
enable() -> None
```

Turn sheet protection on.

### disable

```
disable() -> None
```

Turn sheet protection off.

## WorksheetPageMargins

```
WorksheetPageMargins(left: float = 0.7, right: float = 0.7, top: float = 0.75, bottom: float = 0.75, header: float = 0.3, footer: float = 0.3)
```

`ws.page_margins` in inches (openpyxl's defaults).

## XlsxStyleTable

```
XlsxStyleTable()
```

A parsed `xl/styles.xml` table with append-only style creation.

### empty

```
empty() -> XlsxStyleTable
```

A style table with Excel's default font, fills, border and cell format.

### from\_xml

```
from_xml(xml: bytes | str | None) -> XlsxStyleTable
```

Parse `xl/styles.xml`; empty input gives `empty`.

### add\_named\_style

```
add_named_style(style: NamedStyle) -> int
```

Append a named style to `cellStyleXfs`/`cellStyles`.

### add

```
add(style: Style) -> int
```

Return the XF index for `style`, appending components as needed.

### to\_bytes

```
to_bytes() -> bytes
```

Serialise the table, preserving unrelated style children.

### append\_dxfs

```
append_dxfs(fragments: list[str]) -> list[int]
```

Add differential formats; return the index of each in the table.

`fragments` are `<dxf>` elements in the main namespace. A format equal to one the table holds reuses it, so repeated edits do not leave unused copies behind. Number formats are given this table's ids, so that a format code keeps one id in the workbook.

### style\_at

```
style_at(index: int) -> Style
```

The Style of a cell format index; the default style for an index out of range.

### dxf\_at

```
dxf_at(index: int | None) -> DifferentialStyle | None
```

The differential style at `index`, or None when there is none.

### clone

```
clone() -> XlsxStyleTable
```

Return an independent copy of the table.
