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)[源代码]

基类:openpyxl.descriptors.serialisable.Serialisable

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,

property bottom

A list of cell coordinates that comprise the bottom of the range

property bounds

Vertices of the range as a tuple

property cells
property cols

Return cell coordinates as columns

property coord

Excel-style representation of the range

expand(right=0, down=0, left=0, up=0)[源代码]

Expand the range by the dimensions provided.

参数
  • 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)[源代码]

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

参数

other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range.

返回

the intersecting sheet range.

Raise

ValueError if the other range doesn’t intersect with this range.

isdisjoint(other)[源代码]

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.

参数

other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range.

返回

True if the range has no cells in common with other.

issubset(other)[源代码]

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

参数

other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range

返回

True if range <= other.

issuperset(other)[源代码]

Test whether every cell in other is in this range.

参数

other (openpyxl.worksheet.cell_range.CellRange) – Other sheet range

返回

True if range >= other (or other in range).

property left

A list of cell coordinates that comprise the left-side of the 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’>

property right

A list of cell coordinates that comprise the right-side of the range

property rows

Return cell coordinates as rows

shift(col_shift=0, row_shift=0)[源代码]

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

参数
  • 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

Raise

ValueError if any row or column index < 1

shrink(right=0, bottom=0, left=0, top=0)[源代码]

Shrink the range by the dimensions provided.

参数
  • 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

property size

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

property top

A list of cell coordinates that comprise the top of the range

union(other)[源代码]

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.

参数

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=())[源代码]

基类:openpyxl.descriptors.Strict

add(coord)[源代码]

Add a cell coordinate or CellRange

ranges

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

remove(coord)[源代码]