Worksheet
paper-xlsx 0.2.1 API reference
Represents a worksheet.
Do not create worksheets yourself,
use openpyxl.workbook.Workbook.create_sheet instead
Worksheet(parent, title=None)Attributes
BREAK_COLUMN
attributeBREAK_COLUMN= 2BREAK_NONE
attributeBREAK_NONE= 0BREAK_ROW
attributeBREAK_ROW= 1HeaderFooter
attributeHeaderFooter= HeaderFooter()ORIENTATION_LANDSCAPE
attributeORIENTATION_LANDSCAPE= 'landscape'ORIENTATION_PORTRAIT
attributeORIENTATION_PORTRAIT= 'portrait'PAPERSIZE_A3
attributePAPERSIZE_A3= '8'PAPERSIZE_A4
attributePAPERSIZE_A4= '9'PAPERSIZE_A4_SMALL
attributePAPERSIZE_A4_SMALL= '10'PAPERSIZE_A5
attributePAPERSIZE_A5= '11'PAPERSIZE_EXECUTIVE
attributePAPERSIZE_EXECUTIVE= '7'PAPERSIZE_LEDGER
attributePAPERSIZE_LEDGER= '4'PAPERSIZE_LEGAL
attributePAPERSIZE_LEGAL= '5'PAPERSIZE_LETTER
attributePAPERSIZE_LETTER= '1'PAPERSIZE_LETTER_SMALL
attributePAPERSIZE_LETTER_SMALL= '2'PAPERSIZE_STATEMENT
attributePAPERSIZE_STATEMENT= '6'PAPERSIZE_TABLOID
attributePAPERSIZE_TABLOID= '3'SHEETSTATE_HIDDEN
attributeSHEETSTATE_HIDDEN= 'hidden'SHEETSTATE_VERYHIDDEN
attributeSHEETSTATE_VERYHIDDEN= 'veryHidden'SHEETSTATE_VISIBLE
attributeSHEETSTATE_VISIBLE= 'visible'active_cell
attributeactive_cellarray_formulae
attributearray_formulaeReturns a dictionary of cells with array formulae and the cells in array
column_groups
attributecolumn_groupsReturn a list of column ranges where more than one column
columns
attributecolumnsProduces all cells in the worksheet, by column (see iter_cols)
dimensions
attributedimensionsReturns the result of calculate_dimension
encoding
attributeencodingevenFooter
attributeevenFooterevenHeader
attributeevenHeaderfirstFooter
attributefirstFooterfirstHeader
attributefirstHeaderfreeze_panes
attributefreeze_panesmax_column
attributemax_columnThe maximum column index containing data (1-based)
:type: int
max_row
attributemax_rowThe maximum row index containing data (1-based)
:type: int
merged_cell_ranges
attributemerged_cell_rangesReturn a copy of cell ranges
mime_type
attributemime_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'min_column
attributemin_columnThe minimum column index containing data (1-based)
:type: int
min_row
attributemin_rowThe minimum row index containing data (1-based)
:type: int
oddFooter
attributeoddFooteroddHeader
attributeoddHeaderparent
attributeparentpath
attributepathprint_area
attributeprint_areaThe print area for the worksheet, or None if not set. To set, supply a range like 'A1:D4' or a list of ranges.
print_title_cols
attributeprint_title_colsColumns to be printed at the left side of every page (ex: 'A:C')
print_title_rows
attributeprint_title_rowsRows to be printed at the top of every page (ex: '1:3')
print_titles
attributeprint_titlesrows
attributerowsProduces all cells in the worksheet, by row (see iter_rows)
:type: generator
selected_cell
attributeselected_cellsheet_view
attributesheet_viewshow_gridlines
attributeshow_gridlinestables
attributetablestitle
attributetitlevalues
attributevaluesProduces all cell values in the worksheet, by row
:type: generator
Functions
__delitem__
func__delitem__(key)paramkey__getitem__
func__getitem__(key)Convenience access by Excel style coordinates
The key can be a single cell coordinate 'A1', a range of cells 'A1:D25', individual rows or columns 'A', 4 or ranges of rows or columns 'A:D', 4:10.
Single cells will always be created if they do not exist.
Returns either a single cell or a tuple of rows or columns.
paramkey__iter__
func__iter__()__setitem__
func__setitem__(key, value)paramkeyparamvalueadd_chart
funcadd_chart(chart, anchor=None)Add a chart to the sheet Optionally provide a cell for the top-left anchor
paramchartparamanchor= Noneadd_data_validation
funcadd_data_validation(data_validation)Add a data-validation object to the sheet. The data-validation object defines the type of data-validation to be applied and the cell or range of cells it should apply to.
paramdata_validationadd_image
funcadd_image(img, anchor=None)Add an image to the sheet. Optionally provide a cell for the top-left anchor
paramimgparamanchor= Noneadd_pivot
funcadd_pivot(pivot)parampivotadd_table
funcadd_table(table)Check for duplicate name in definedNames and other worksheet tables before adding table.
paramtableallowed_values
funcallowed_values(cell)The data-validation vocabulary for cell (address string or
Cell), or None when no list-type validation covers it
(paper-xlsx).
paramcellappend
funcappend(iterable)paramiterableappend_table_row
funcappend_table_row(table_name, values)Append one row to a supported named table atomically.
paramtable_namestrName of the table to expand.
paramvaluesiterable | mappingRow values as a sequence or column-name mapping.
Returns
NoneNone.
calculate_dimension
funccalculate_dimension()Return the minimum bounding range for all cells containing data (ex. 'A1:M24')
:rtype: string
cell
funccell(row, column, value=None)Returns a cell object based on the given coordinates.
Usage: cell(row=15, column=1, value=5)
Calling cell creates cells in memory when they
are first accessed.
paramrowintrow index of the cell (e.g. 4)
paramcolumnintcolumn index of the cell (e.g. 3)
paramvaluenumeric, ``datetime.time``, string, bool, | none= Nonevalue of the cell (e.g. 5)
delete_cols
funcdelete_cols(idx, amount=1)Delete column or columns from col==idx
Under preserve=True on a loaded sheet, references into the
shifted range are rewritten and an AddressRemap is returned;
a delete that would strand a reference refuses with
UnsupportedStructureError and changes nothing. Stock loads and
added sheets keep upstream behaviour and return None.
paramidxparamamount= 1delete_rows
funcdelete_rows(idx, amount=1)Delete row or rows from row==idx
Under preserve=True on a loaded sheet, references into the
shifted range are rewritten and an AddressRemap is returned;
a delete that would strand a reference (or drop cells a chart or
name still points at) refuses with UnsupportedStructureError
and changes nothing. Stock loads and added sheets keep upstream
behaviour and return None.
paramidxparamamount= 1insert_cols
funcinsert_cols(idx, amount=1)Insert column or columns before col==idx
Under preserve=True on a loaded sheet, references into the
shifted range are rewritten and an AddressRemap is returned;
a shift that would strand a reference refuses with
UnsupportedStructureError and changes nothing. Stock loads and
added sheets keep upstream behaviour and return None.
paramidxparamamount= 1insert_rows
funcinsert_rows(idx, amount=1)Insert row or rows before row==idx
Under preserve=True on a loaded sheet the fork rewrites every
reference that points into the shifted range (formulas, defined
names, chart series) and returns an AddressRemap so pre-edit
addresses can be remapped; a shift that would strand a reference it
cannot rewrite refuses with UnsupportedStructureError and
changes nothing. Stock loads and in-session-added sheets keep the
upstream behaviour — references are NOT updated — and return
None.
paramidxparamamount= 1iter_cols
funciter_cols(min_col=None, max_col=None, min_row=None, max_row=None, values_only=False)Produces cells from the worksheet, by column. Specify the iteration range using indices of rows and columns.
If no indices are specified the range starts at A1.
If no cells are in the worksheet an empty tuple will be returned.
parammin_colint= Nonesmallest column index (1-based index)
parammax_colint= Nonelargest column index (1-based index)
parammin_rowint= Nonesmallest row index (1-based index)
parammax_rowint= Nonelargest row index (1-based index)
paramvalues_onlybool= Falsewhether only cell values should be returned
iter_rows
funciter_rows(min_row=None, max_row=None, min_col=None, max_col=None, values_only=False)Produces cells from the worksheet, by row. Specify the iteration range using indices of rows and columns.
If no indices are specified the range starts at A1.
If no cells are in the worksheet an empty tuple will be returned.
parammin_rowint= Nonesmallest row index (1-based index)
parammax_rowint= Nonelargest row index (1-based index)
parammin_colint= Nonesmallest column index (1-based index)
parammax_colint= Nonelargest column index (1-based index)
paramvalues_onlybool= Falsewhether only cell values should be returned
merge_cells
funcmerge_cells(range_string=None, start_row=None, start_column=None, end_row=None, end_column=None)Set merge on a cell range. Range is a cell range (e.g. A1:E1)
paramrange_string= Noneparamstart_row= Noneparamstart_column= Noneparamend_row= Noneparamend_column= Nonemove_range
funcmove_range(cell_range, rows=0, cols=0, translate=False)Move a cell range by the number of rows and/or columns: down if rows > 0 and up if rows < 0 right if cols > 0 and left if cols < 0 Existing cells will be overwritten. Formulae and references will not be updated.
Under preserve=True the move lands as tracked cell edits and
refuses with UnsupportedStructureError (changing nothing) when
it cannot keep the sheet coherent — e.g. merged ranges, tables,
conditional formatting or data validation intersecting either
rectangle, or outside formulas that reference the moved block.
paramcell_rangeparamrows= 0paramcols= 0paramtranslate= Falsereplace_image
funcreplace_image(target, replacement, *, name=None)Replace one loaded image while preserving its drawing anchor.
paramtargetopenpyxl.drawing.image.Image | strLoaded image or its anchor coordinate.
paramreplacementopenpyxl.drawing.image.Image | path - likeReplacement image or image source.
paramnamestr | None= NoneOptional image name used to resolve an ambiguous anchor.
Returns
openpyxl.drawing.image.ImageThe loaded image selected for replacement.
set_printer_settings
funcset_printer_settings(paper_size, orientation)Set printer settings
parampaper_sizeparamorientationunmerge_cells
funcunmerge_cells(range_string=None, start_row=None, start_column=None, end_row=None, end_column=None)Remove merge on a cell range. Range is a cell range (e.g. A1:E1)
paramrange_string= Noneparamstart_row= Noneparamstart_column= Noneparamend_row= Noneparamend_column= None