openpyxl.worksheet.cell_range module¶

class `openpyxl.worksheet.cell_range.``CellRange`(range_string=None, min_col=None, min_row=None, max_col=None, max_row=None, title=None)[source]

Represents a range in a sheet: title and coordinates.

This object is used to perform operations on ranges, like:

• shift, expand or shrink
• union/intersection with another sheet range,

We can check whether a range is:

• equal or not equal to another,
• disjoint of another,
• contained in another.

We can get:

• the size of a range.
• the range bounds (vertices)
• the coordinates,
• the string representation,
`bounds`

Vertices of the range as a tuple

`coord`

Excel-style representation of the range

`expand`(right=0, down=0, left=0, up=0)[source]

Expand the range by the dimensions provided.

Parameters: right (int) – expand range to the right by this number of cells down (int) – expand range down by this number of cells left (int) – expand range to the left by this number of cells up (int) – expand range up by this number of cells
`intersection`(other)[source]

Return a new range with cells common to this range and other

Parameters: other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range. the intersecting sheet range. `ValueError` if the other range doesn’t intersect with this range.
`isdisjoint`(other)[source]

Return `True` if this range has no cell in common with other. Ranges are disjoint if and only if their intersection is the empty range.

Parameters: other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range. `True` if the range has no cells in common with other.
`issubset`(other)[source]

Test whether every cell in this range is also in other.

Parameters: other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range `True` if range <= other.
`issuperset`(other)[source]

Test whether every cell in other is in this range.

Parameters: other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range `True` if range >= other (or other in range).
`max_col`

Values must be of type <class ‘int’>

`max_row`

Values must be of type <class ‘int’>

`min_col`

Values must be of type <class ‘int’>

`min_row`

Values must be of type <class ‘int’>

`shift`(col_shift=0, row_shift=0)[source]

Shift the range according to the shift values (col_shift, row_shift).

Parameters: col_shift (int) – number of columns to be moved by, can be negative row_shift (int) – number of rows to be moved by, can be negative `ValueError` if any row or column index < 1
`shrink`(right=0, bottom=0, left=0, top=0)[source]

Shrink the range by the dimensions provided.

Parameters: right (int) – shrink range from the right by this number of cells down (int) – shrink range from the top by this number of cells left (int) – shrink range from the left by this number of cells up (int) – shrink range from the bottown by this number of cells
`size`

Return the size of the range as a dictionary of rows and columns.

`union`(other)[source]

Return the minimal superset of this range and other. This new range will contain all cells from this range, other, and any additional cells required to form a rectangular `CellRange`.

Parameters: other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range. a `CellRange` that is a superset of this and other.
class `openpyxl.worksheet.cell_range.``MultiCellRange`(ranges=())[source]
`add`(coord)[source]

Add a cell coordinate or CellRange

`ranges`

A sequence (list or tuple) that may only contain objects of the declared type

`remove`(coord)[source]