Workbook model¶
load_workbook and the openpyxl-like objects it returns.
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 |
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 |
False
|
rich_text
|
bool
|
Preserve rich-text runs as |
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.
Source code in src/xlspy/workbook/_reader.py
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 | |
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.
Source code in src/xlspy/workbook/_workbook.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
sheetnames
property
¶
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
property
writable
¶
read_only: bool
True for a workbook loaded with read_only=True, which cannot be saved.
excel_base_date
property
¶
excel_base_date: datetime
The base date of serial date numbers, as openpyxl names epoch.
style_names
property
¶
style_names: list[str]
The names of the workbook's named styles, as openpyxl lists them.
active
property
writable
¶
active: Worksheet
The active worksheet; set it with a worksheet or its index.
properties
property
writable
¶
properties: DocumentProperties
The document properties: title, author, dates and so on.
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.
Source code in src/xlspy/workbook/_workbook.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
set_vba_name
¶
set_vba_name(name: str) -> None
Set the VBA project's code name (workbookPr/@codeName).
Source code in src/xlspy/workbook/_workbook.py
137 138 139 | |
get_sheet_by_name
¶
get_sheet_by_name(name: str) -> Worksheet
Return the worksheet called name; the same as wb[name].
Source code in src/xlspy/workbook/_workbook.py
262 263 264 | |
get_sheet_names
¶
get_sheet_names() -> list[str]
The worksheet names, as openpyxl's deprecated alias for sheetnames.
Source code in src/xlspy/workbook/_workbook.py
266 267 268 | |
get_index
¶
get_index(worksheet: Worksheet | str) -> int
Return the 0-based position of worksheet or its title, as openpyxl's alias for index.
Source code in src/xlspy/workbook/_workbook.py
270 271 272 | |
index
¶
index(worksheet: Worksheet | str) -> int
Return the 0-based position of worksheet, or of a sheet title.
Source code in src/xlspy/workbook/_workbook.py
274 275 276 277 278 279 280 281 | |
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.
Source code in src/xlspy/workbook/_workbook.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
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.
Source code in src/xlspy/workbook/_workbook.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
move_sheet
¶
move_sheet(sheet: Worksheet | str, offset: int = 0) -> None
Move a sheet offset positions (negative: towards the front), as openpyxl does.
Source code in src/xlspy/workbook/_workbook.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
remove
¶
remove(worksheet: Worksheet) -> None
Remove worksheet from the workbook.
Source code in src/xlspy/workbook/_workbook.py
341 342 343 344 345 346 347 348 349 | |
remove_sheet
¶
remove_sheet(worksheet: Worksheet) -> None
Remove worksheet, as openpyxl's deprecated alias for remove.
Source code in src/xlspy/workbook/_workbook.py
351 352 353 | |
copy_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.
Source code in src/xlspy/workbook/_workbook.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
add_named_style
¶
add_named_style(style: NamedStyle) -> None
Register a NamedStyle so that cells can use it by name.
Source code in src/xlspy/workbook/_workbook.py
426 427 428 429 430 431 432 | |
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(...).
Source code in src/xlspy/workbook/_workbook.py
434 435 436 437 438 439 440 441 442 443 444 445 | |
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.
Source code in src/xlspy/workbook/_workbook.py
517 518 519 520 521 522 523 524 525 526 527 528 | |
close
¶
close() -> None
Release the files held by a loaded or read-only workbook.
Source code in src/xlspy/workbook/_workbook.py
530 531 532 533 534 535 536 537 538 539 540 541 542 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
title
property
writable
¶
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.
merged_cell_ranges
property
¶
merged_cell_ranges: list[str]
A copy of the merged range strings, as openpyxl's deprecated alias.
array_formulae
property
¶
array_formulae: dict[str, str]
Array formula anchors and the range each one fills, as openpyxl maps them.
column_groups
property
¶
column_groups: list[str]
The column ranges that span more than one column, such as "A:C".
column_dimensions
property
¶
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
property
¶
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
property
writable
¶
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
property
writable
¶
auto_filter: AutoFilter
The sheet's AutoFilter: its range, filter columns and sort state.
sheet_properties
property
¶
sheet_properties: SheetProperties
Sheet properties such as the tab colour and outline settings.
sheet_view
property
¶
sheet_view: SheetView
The first sheet view: zoom, grid lines, selection and panes.
defined_names
property
¶
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
property
writable
¶
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
property
¶
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
property
¶
active_cell: str | None
The active cell of the first selection, or None when the view has none.
selected_cell
property
¶
selected_cell: str | None
The selected range of the first selection, or None when the view has none.
show_gridlines
property
writable
¶
show_gridlines: bool | None
Whether the sheet view shows grid lines; None leaves Excel's default.
page_margins
property
writable
¶
page_margins: WorksheetPageMargins
Page margins for printing, in inches.
min_row
property
¶
min_row: int
Always 1: the used range is reported from A1, as openpyxl does for new sheets.
min_column
property
¶
min_column: int
Always 1: the used range is reported from A1, as openpyxl does for new sheets.
dimensions
property
¶
dimensions: str
The used range from A1, such as "A1:D20"; "A1:A1" for an empty sheet.
rows
property
¶
rows: Iterator[tuple[Cell, ...]]
The rows of the used range as tuples of cells (see iter_rows).
columns
property
¶
columns: Iterator[tuple[Cell, ...]]
The columns of the used range as tuples of cells (see iter_cols).
conditional_formatting
property
¶
conditional_formatting: ConditionalFormattingList
The sheet's conditional formatting, grouped by range.
oddHeader
property
¶
oddHeader: HeaderFooterItem
The header of odd pages (all pages unless odd and even pages differ).
oddFooter
property
¶
oddFooter: HeaderFooterItem
The footer of odd pages (all pages unless odd and even pages differ).
evenHeader
property
¶
evenHeader: HeaderFooterItem
The header of even pages, when odd and even pages differ.
evenFooter
property
¶
evenFooter: HeaderFooterItem
The footer of even pages, when odd and even pages differ.
firstHeader
property
¶
firstHeader: HeaderFooterItem
The header of the first page, when the first page differs.
firstFooter
property
¶
firstFooter: HeaderFooterItem
The footer of the first page, when the first page differs.
print_title_rows
property
writable
¶
print_title_rows: str | None
Rows repeated at the top of every printed page, such as "1:2".
print_title_cols
property
writable
¶
print_title_cols: str | None
Columns repeated at the left of every printed page, such as "A:B".
print_titles
property
¶
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.
Source code in src/xlspy/workbook/_worksheet.py
451 452 453 | |
insert_rows
¶
insert_rows(idx: int, amount: int = 1) -> None
Insert amount empty rows before row idx.
Source code in src/xlspy/workbook/_worksheet.py
568 569 570 | |
delete_rows
¶
delete_rows(idx: int, amount: int = 1) -> None
Delete amount rows starting at row idx; the rows below move up.
Source code in src/xlspy/workbook/_worksheet.py
572 573 574 | |
insert_cols
¶
insert_cols(idx: int, amount: int = 1) -> None
Insert amount empty columns before column idx (1-based).
Source code in src/xlspy/workbook/_worksheet.py
576 577 578 | |
delete_cols
¶
delete_cols(idx: int, amount: int = 1) -> None
Delete amount columns starting at column idx; the rest move left.
Source code in src/xlspy/workbook/_worksheet.py
580 581 582 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
584 585 586 587 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
590 591 592 593 594 595 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
597 598 599 600 601 602 603 | |
add_table
¶
add_table(table: ExcelTable | Table) -> None
Add a table: an ExcelTable or an openpyxl-style Table.
Source code in src/xlspy/workbook/_worksheet.py
605 606 607 608 | |
add_data_validation
¶
add_data_validation(data_validation: DataValidation) -> None
Add a data validation rule.
Source code in src/xlspy/workbook/_worksheet.py
610 611 612 613 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
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.
Source code in src/xlspy/workbook/_reader.py
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 | |
max_row
property
¶
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
property
¶
max_column: int | None
The last column of the dimension stored in the file, or None when it stores none.
See calculate_dimension.
dimensions
property
¶
dimensions: str
The used range; raises ValueError when the file stores no dimension.
page_margins
property
writable
¶
page_margins: WorksheetPageMargins
Page margins for printing, in inches.
title
property
writable
¶
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.
merged_cell_ranges
property
¶
merged_cell_ranges: list[str]
A copy of the merged range strings, as openpyxl's deprecated alias.
array_formulae
property
¶
array_formulae: dict[str, str]
Array formula anchors and the range each one fills, as openpyxl maps them.
column_groups
property
¶
column_groups: list[str]
The column ranges that span more than one column, such as "A:C".
column_dimensions
property
¶
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
property
¶
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
property
writable
¶
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
property
writable
¶
auto_filter: AutoFilter
The sheet's AutoFilter: its range, filter columns and sort state.
sheet_properties
property
¶
sheet_properties: SheetProperties
Sheet properties such as the tab colour and outline settings.
sheet_view
property
¶
sheet_view: SheetView
The first sheet view: zoom, grid lines, selection and panes.
defined_names
property
¶
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
property
writable
¶
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
property
¶
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
property
¶
active_cell: str | None
The active cell of the first selection, or None when the view has none.
selected_cell
property
¶
selected_cell: str | None
The selected range of the first selection, or None when the view has none.
show_gridlines
property
writable
¶
show_gridlines: bool | None
Whether the sheet view shows grid lines; None leaves Excel's default.
rows
property
¶
rows: Iterator[tuple[Cell, ...]]
The rows of the used range as tuples of cells (see iter_rows).
columns
property
¶
columns: Iterator[tuple[Cell, ...]]
The columns of the used range as tuples of cells (see iter_cols).
conditional_formatting
property
¶
conditional_formatting: ConditionalFormattingList
The sheet's conditional formatting, grouped by range.
oddHeader
property
¶
oddHeader: HeaderFooterItem
The header of odd pages (all pages unless odd and even pages differ).
oddFooter
property
¶
oddFooter: HeaderFooterItem
The footer of odd pages (all pages unless odd and even pages differ).
evenHeader
property
¶
evenHeader: HeaderFooterItem
The header of even pages, when odd and even pages differ.
evenFooter
property
¶
evenFooter: HeaderFooterItem
The footer of even pages, when odd and even pages differ.
firstHeader
property
¶
firstHeader: HeaderFooterItem
The header of the first page, when the first page differs.
firstFooter
property
¶
firstFooter: HeaderFooterItem
The footer of the first page, when the first page differs.
print_title_rows
property
writable
¶
print_title_rows: str | None
Rows repeated at the top of every printed page, such as "1:2".
print_title_cols
property
writable
¶
print_title_cols: str | None
Columns repeated at the left of every printed page, such as "A:B".
print_titles
property
¶
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.
Source code in src/xlspy/workbook/_reader.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 | |
reset_dimensions
¶
reset_dimensions() -> None
Ignore a wrong stored dimension, as openpyxl's reset_dimensions().
Source code in src/xlspy/workbook/_reader.py
1521 1522 1523 | |
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.
Source code in src/xlspy/workbook/_reader.py
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
iter_cols
¶
iter_cols(*args: Any, **kwargs: Any) -> NoReturn
Not available in read-only mode: raises AttributeError.
Source code in src/xlspy/workbook/_reader.py
1624 1625 1626 | |
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.
Source code in src/xlspy/workbook/_reader.py
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 | |
append
¶
append(iterable: Iterable[Any]) -> NoReturn
Not available: read-only worksheets cannot be modified.
Source code in src/xlspy/workbook/_reader.py
1692 1693 1694 | |
insert_rows
¶
insert_rows(idx: int, amount: int = 1) -> None
Insert amount empty rows before row idx.
Source code in src/xlspy/workbook/_worksheet.py
568 569 570 | |
delete_rows
¶
delete_rows(idx: int, amount: int = 1) -> None
Delete amount rows starting at row idx; the rows below move up.
Source code in src/xlspy/workbook/_worksheet.py
572 573 574 | |
insert_cols
¶
insert_cols(idx: int, amount: int = 1) -> None
Insert amount empty columns before column idx (1-based).
Source code in src/xlspy/workbook/_worksheet.py
576 577 578 | |
delete_cols
¶
delete_cols(idx: int, amount: int = 1) -> None
Delete amount columns starting at column idx; the rest move left.
Source code in src/xlspy/workbook/_worksheet.py
580 581 582 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
584 585 586 587 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
590 591 592 593 594 595 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
597 598 599 600 601 602 603 | |
add_table
¶
add_table(table: ExcelTable | Table) -> None
Add a table: an ExcelTable or an openpyxl-style Table.
Source code in src/xlspy/workbook/_worksheet.py
605 606 607 608 | |
add_data_validation
¶
add_data_validation(data_validation: DataValidation) -> None
Add a data validation rule.
Source code in src/xlspy/workbook/_worksheet.py
610 611 612 613 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
WriteOnlyWorksheet
¶
WriteOnlyWorksheet(workbook: Workbook, title: str, *, index: int | None = None)
Bases: Worksheet
Streaming-friendly sheet that stores rows rather than Cell objects.
Source code in src/xlspy/workbook/_worksheet.py
1106 1107 1108 1109 1110 1111 | |
page_margins
property
writable
¶
page_margins: WorksheetPageMargins
Page margins for printing, in inches.
title
property
writable
¶
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.
merged_cell_ranges
property
¶
merged_cell_ranges: list[str]
A copy of the merged range strings, as openpyxl's deprecated alias.
array_formulae
property
¶
array_formulae: dict[str, str]
Array formula anchors and the range each one fills, as openpyxl maps them.
column_groups
property
¶
column_groups: list[str]
The column ranges that span more than one column, such as "A:C".
column_dimensions
property
¶
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
property
¶
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
property
writable
¶
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
property
writable
¶
auto_filter: AutoFilter
The sheet's AutoFilter: its range, filter columns and sort state.
sheet_properties
property
¶
sheet_properties: SheetProperties
Sheet properties such as the tab colour and outline settings.
sheet_view
property
¶
sheet_view: SheetView
The first sheet view: zoom, grid lines, selection and panes.
defined_names
property
¶
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
property
writable
¶
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
property
¶
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
property
¶
active_cell: str | None
The active cell of the first selection, or None when the view has none.
selected_cell
property
¶
selected_cell: str | None
The selected range of the first selection, or None when the view has none.
show_gridlines
property
writable
¶
show_gridlines: bool | None
Whether the sheet view shows grid lines; None leaves Excel's default.
min_row
property
¶
min_row: int
Always 1: the used range is reported from A1, as openpyxl does for new sheets.
min_column
property
¶
min_column: int
Always 1: the used range is reported from A1, as openpyxl does for new sheets.
dimensions
property
¶
dimensions: str
The used range from A1, such as "A1:D20"; "A1:A1" for an empty sheet.
rows
property
¶
rows: Iterator[tuple[Cell, ...]]
The rows of the used range as tuples of cells (see iter_rows).
columns
property
¶
columns: Iterator[tuple[Cell, ...]]
The columns of the used range as tuples of cells (see iter_cols).
conditional_formatting
property
¶
conditional_formatting: ConditionalFormattingList
The sheet's conditional formatting, grouped by range.
oddHeader
property
¶
oddHeader: HeaderFooterItem
The header of odd pages (all pages unless odd and even pages differ).
oddFooter
property
¶
oddFooter: HeaderFooterItem
The footer of odd pages (all pages unless odd and even pages differ).
evenHeader
property
¶
evenHeader: HeaderFooterItem
The header of even pages, when odd and even pages differ.
evenFooter
property
¶
evenFooter: HeaderFooterItem
The footer of even pages, when odd and even pages differ.
firstHeader
property
¶
firstHeader: HeaderFooterItem
The header of the first page, when the first page differs.
firstFooter
property
¶
firstFooter: HeaderFooterItem
The footer of the first page, when the first page differs.
print_title_rows
property
writable
¶
print_title_rows: str | None
Rows repeated at the top of every printed page, such as "1:2".
print_title_cols
property
writable
¶
print_title_cols: str | None
Columns repeated at the left of every printed page, such as "A:B".
print_titles
property
¶
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.
Source code in src/xlspy/workbook/_worksheet.py
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
cell
¶
cell(row: int, column: int | str, value: Any = None) -> Cell
Not available in write-only mode: raises ValueError. Use append.
Source code in src/xlspy/workbook/_worksheet.py
1160 1161 1162 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
1164 1165 1166 1167 1168 1169 1170 | |
calculate_dimension
¶
calculate_dimension(force: bool = False) -> str
Return dimensions. force is accepted for openpyxl compatibility.
Source code in src/xlspy/workbook/_worksheet.py
451 452 453 | |
insert_rows
¶
insert_rows(idx: int, amount: int = 1) -> None
Insert amount empty rows before row idx.
Source code in src/xlspy/workbook/_worksheet.py
568 569 570 | |
delete_rows
¶
delete_rows(idx: int, amount: int = 1) -> None
Delete amount rows starting at row idx; the rows below move up.
Source code in src/xlspy/workbook/_worksheet.py
572 573 574 | |
insert_cols
¶
insert_cols(idx: int, amount: int = 1) -> None
Insert amount empty columns before column idx (1-based).
Source code in src/xlspy/workbook/_worksheet.py
576 577 578 | |
delete_cols
¶
delete_cols(idx: int, amount: int = 1) -> None
Delete amount columns starting at column idx; the rest move left.
Source code in src/xlspy/workbook/_worksheet.py
580 581 582 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
584 585 586 587 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
590 591 592 593 594 595 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
597 598 599 600 601 602 603 | |
add_table
¶
add_table(table: ExcelTable | Table) -> None
Add a table: an ExcelTable or an openpyxl-style Table.
Source code in src/xlspy/workbook/_worksheet.py
605 606 607 608 | |
add_data_validation
¶
add_data_validation(data_validation: DataValidation) -> None
Add a data validation rule.
Source code in src/xlspy/workbook/_worksheet.py
610 611 612 613 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
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.
Source code in src/xlspy/workbook/_worksheet.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 | |
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).
Source code in src/xlspy/workbook/_worksheet.py
1180 1181 1182 1183 1184 1185 1186 1187 | |
charts
property
¶
charts: list[Chart]
The chart of the sheet, as a list of at most one for a new chartsheet.
add_chart
¶
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).
Source code in src/xlspy/workbook/_worksheet.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 | |
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.
Source code in src/xlspy/workbook/_cell.py
78 79 80 81 82 83 84 85 86 87 88 89 90 | |
value
property
writable
¶
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
property
¶
formula: Formula | ArrayFormula | DataTableFormula | str | None
The formula object or text without its leading =, or None.
data_type
property
¶
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
property
¶
internal_value: Any
The stored value; None for a formula cell that holds no cached result.
base_date
property
¶
base_date: datetime
The workbook's epoch, the base date of serial date numbers (1899-12-30).
threaded_comment
property
writable
¶
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.
has_style
property
¶
has_style: bool
True when the cell has a style other than the workbook default.
font
property
writable
¶
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
property
writable
¶
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
property
writable
¶
border: Border
The cell border; a cell without one reports openpyxl's empty border.
alignment
property
writable
¶
alignment: Alignment
The cell alignment; a cell without one reports openpyxl's default.
protection
property
writable
¶
protection: Protection
The cell protection (locked, hidden).
A cell without explicit protection reports openpyxl's locked, visible default.
quotePrefix
property
¶
quotePrefix: bool
True when the cell's format sets Excel's quote prefix, as openpyxl's.
pivotButton
property
¶
pivotButton: bool
True when the cell's format sets Excel's pivot-button flag.
number_format
property
writable
¶
number_format: str
The number format code; "General" when none is set.
style
property
writable
¶
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".
Source code in src/xlspy/workbook/_cell.py
411 412 413 414 415 416 | |
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.
Source code in src/xlspy/workbook/_cell.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
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.
Source code in src/xlspy/workbook/_cell.py
516 517 518 519 520 521 | |
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.
Source code in src/xlspy/workbook/_cell.py
78 79 80 81 82 83 84 85 86 87 88 89 90 | |
formula
property
¶
formula: Formula | ArrayFormula | DataTableFormula | str | None
The formula object or text without its leading =, or None.
data_type
property
¶
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
property
¶
internal_value: Any
The stored value; None for a formula cell that holds no cached result.
base_date
property
¶
base_date: datetime
The workbook's epoch, the base date of serial date numbers (1899-12-30).
threaded_comment
property
writable
¶
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.
has_style
property
¶
has_style: bool
True when the cell has a style other than the workbook default.
font
property
writable
¶
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
property
writable
¶
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
property
writable
¶
border: Border
The cell border; a cell without one reports openpyxl's empty border.
alignment
property
writable
¶
alignment: Alignment
The cell alignment; a cell without one reports openpyxl's default.
protection
property
writable
¶
protection: Protection
The cell protection (locked, hidden).
A cell without explicit protection reports openpyxl's locked, visible default.
quotePrefix
property
¶
quotePrefix: bool
True when the cell's format sets Excel's quote prefix, as openpyxl's.
pivotButton
property
¶
pivotButton: bool
True when the cell's format sets Excel's pivot-button flag.
number_format
property
writable
¶
number_format: str
The number format code; "General" when none is set.
style
property
writable
¶
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".
Source code in src/xlspy/workbook/_cell.py
411 412 413 414 415 416 | |
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.
Source code in src/xlspy/workbook/_cell.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
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.
Source code in src/xlspy/workbook/_cell.py
516 517 518 519 520 521 | |
ReadOnlyCell
¶
ReadOnlyCell(row: int, column: int, value: Any, number_format: str = 'General')
A cell value streamed from a read-only worksheet (as openpyxl's).
Source code in src/xlspy/workbook/_reader.py
1392 1393 1394 1395 1396 | |
WriteOnlyCell
¶
WriteOnlyCell(worksheet: Any, value: Any = None)
A value with optional style, used with WriteOnlyWorksheet.append.
Source code in src/xlspy/workbook/_cell.py
555 556 557 558 559 560 561 562 563 564 565 | |
CellRange
¶
Bases: str
An A1 range string with openpyxl-style boundary properties.
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.
Source code in src/xlspy/workbook/_coords.py
130 131 132 133 134 135 136 137 138 139 140 141 | |
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.
Source code in src/xlspy/workbook/_coords.py
143 144 145 146 147 148 149 150 151 152 153 154 | |
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.
Source code in src/xlspy/workbook/_coords.py
156 157 158 | |
union
¶
Return the smallest range that covers this range and other.
Source code in src/xlspy/workbook/_coords.py
160 161 162 163 164 165 166 167 168 | |
intersection
¶
Return the cells this range shares with other.
Raises ValueError when the ranges do not overlap.
Source code in src/xlspy/workbook/_coords.py
170 171 172 173 174 175 176 177 178 179 180 181 182 | |
isdisjoint
¶
isdisjoint(other: CellRange | str) -> bool
True when this range and other share no cell.
Source code in src/xlspy/workbook/_coords.py
184 185 186 187 188 189 190 191 192 | |
issubset
¶
issubset(other: CellRange | str) -> bool
True when every cell of this range is in other.
Source code in src/xlspy/workbook/_coords.py
194 195 196 197 198 199 200 | |
issuperset
¶
issuperset(other: CellRange | str) -> bool
True when every cell of other is in this range.
Source code in src/xlspy/workbook/_coords.py
202 203 204 205 | |
MultiCellRange
¶
MultiCellRange(ranges: Iterable[str] | None = None)
Several cell ranges, such as a sheet's merged cells, in the order added.
Source code in src/xlspy/workbook/_coords.py
277 278 279 280 281 282 283 284 | |
ranges
property
writable
¶
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.
Source code in src/xlspy/workbook/_coords.py
306 307 308 309 310 311 312 313 314 | |
remove
¶
remove(value: str) -> None
Remove a range; raises ValueError when it is not present.
Source code in src/xlspy/workbook/_coords.py
316 317 318 319 320 321 322 323 324 325 | |
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.
Source code in src/xlspy/workbook/_coords.py
327 328 329 330 331 | |
Dimension
¶
Dimension(index: str | int)
The size, visibility and outline settings of a row or column, with openpyxl's attribute names.
Source code in src/xlspy/workbook/_dimensions.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
ColumnDimension
¶
ColumnDimension(index: str | int)
Bases: Dimension
A column's width, visibility and outline level: ws.column_dimensions["B"].
Source code in src/xlspy/workbook/_dimensions.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
outline_level
property
writable
¶
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].
Source code in src/xlspy/workbook/_dimensions.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
DimensionHolder
¶
DimensionHolder(factory: Callable[[Any], Dimension], transform: Callable[[Any], Any])
Bases: dict[Any, Any]
Source code in src/xlspy/workbook/_dimensions.py
64 65 66 67 | |
get
¶
get(key: Any, default: Any = None) -> Any
Like dict.get, without creating an entry; the key may be a letter or a number.
Source code in src/xlspy/workbook/_dimensions.py
78 79 80 | |
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.
Source code in src/xlspy/workbook/_dimensions.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
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.
Source code in src/xlspy/workbook/_tables.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
display_name
property
¶
display_name: str | None
The table name shown in Excel; the same as displayName.
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.
Source code in src/xlspy/workbook/_tables.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
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.
Source code in src/xlspy/workbook/_tables.py
119 120 121 122 123 124 125 126 127 128 129 130 131 | |
AutoFilter
dataclass
¶
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.
Source code in src/xlspy/workbook/_properties.py
417 418 419 420 421 422 | |
add_sort_condition
¶
add_sort_condition(ref: str, descending: bool = False) -> None
Sort by the cells of ref, descending when asked.
Source code in src/xlspy/workbook/_properties.py
424 425 426 427 428 | |
DefinedNameList
¶
DefinedNameList(workbook: Workbook | None = None, definitions: Iterable[DefinedName] | None = None)
A list/dict hybrid of DefinedName entries.
Source code in src/xlspy/workbook/_properties.py
88 89 90 91 92 | |
keys
¶
keys() -> list[str]
The defined names' names, as a dict-like view over the list.
Source code in src/xlspy/workbook/_properties.py
135 136 137 | |
values
¶
values() -> list[DefinedName]
The defined names, as a dict-like view over the list.
Source code in src/xlspy/workbook/_properties.py
139 140 141 | |
items
¶
items() -> list[tuple[str, DefinedName]]
The names and their definitions, as a dict-like view over the list.
Source code in src/xlspy/workbook/_properties.py
143 144 145 | |
get
¶
get(name: str, default: object = None) -> object
The definition called name, or default when there is none.
Source code in src/xlspy/workbook/_properties.py
147 148 149 150 151 152 | |
add
¶
add(definition: DefinedName, *, stage: bool = True) -> None
Add a defined name, replacing one with the same name and scope.
Source code in src/xlspy/workbook/_properties.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
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.
Source code in src/xlspy/workbook/_properties.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
DocumentProperties
dataclass
¶
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)
CustomPropertyList
¶
Bases: list
A list of custom document properties, keyed by name for convenience.
CalcProperties
dataclass
¶
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
dataclass
¶
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
dataclass
¶
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
dataclass
¶
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
dataclass
¶
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
dataclass
¶
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
dataclass
¶
Pane(xSplit: float | int | None = None, ySplit: float | int | None = None, topLeftCell: str | None = None, activePane: str = 'topLeft', state: str = 'split')
Selection
dataclass
¶
Selection(pane: str | None = None, activeCell: str = 'A1', activeCellId: int | None = None, sqref: str = 'A1')
Outline
dataclass
¶
Outline(applyStyles: bool | None = None, summaryBelow: bool | None = None, summaryRight: bool | None = None, showOutlineSymbols: bool | None = None)
WorksheetProtection
dataclass
¶
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.
Source code in src/xlspy/workbook/_properties.py
498 499 500 501 502 | |
enable
¶
enable() -> None
Turn sheet protection on.
Source code in src/xlspy/workbook/_properties.py
504 505 506 | |
disable
¶
disable() -> None
Turn sheet protection off.
Source code in src/xlspy/workbook/_properties.py
508 509 510 | |
WorksheetPageMargins
dataclass
¶
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.
Source code in src/xlspy/workbook/_styles.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
empty
classmethod
¶
empty() -> XlsxStyleTable
A style table with Excel's default font, fills, border and cell format.
Source code in src/xlspy/workbook/_styles.py
396 397 398 399 400 401 | |
from_xml
classmethod
¶
from_xml(xml: bytes | str | None) -> XlsxStyleTable
Parse xl/styles.xml; empty input gives empty.
Source code in src/xlspy/workbook/_styles.py
403 404 405 406 407 408 409 410 411 412 413 414 415 | |
add_named_style
¶
add_named_style(style: NamedStyle) -> int
Append a named style to cellStyleXfs/cellStyles.
Source code in src/xlspy/workbook/_styles.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
add
¶
add(style: Style) -> int
Return the XF index for style, appending components as needed.
Source code in src/xlspy/workbook/_styles.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | |
to_bytes
¶
to_bytes() -> bytes
Serialise the table, preserving unrelated style children.
Source code in src/xlspy/workbook/_styles.py
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | |
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.
Source code in src/xlspy/workbook/_styles.py
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 | |
style_at
¶
style_at(index: int) -> Style
The Style of a cell format index; the default style for an index out of range.
Source code in src/xlspy/workbook/_styles.py
1065 1066 1067 1068 1069 | |
dxf_at
¶
dxf_at(index: int | None) -> DifferentialStyle | None
The differential style at index, or None when there is none.
Source code in src/xlspy/workbook/_styles.py
1071 1072 1073 1074 1075 | |
clone
¶
clone() -> XlsxStyleTable
Return an independent copy of the table.
Source code in src/xlspy/workbook/_styles.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | |