U o^9@spddlmZddlmZddlmZmZddlmZddlmZm Z m Z m Z GdddeZ Gdd d eZ d S) )copy)Strict)MinMaxSequence) Serialisable)range_boundariesrange_to_tupleget_column_letterquote_sheetnamec@sdeZdZdZeddedZeddedZeddedZeddedZ d@ddZ e d d Z e d d Z e d dZe ddZddZddZddZddZdAddZddZddZd d!ZeZd"d#Zd$d%ZeZd&d'Zd(d)Zd*d+Zd,d-ZeZ d.d/Z!e!Z"d0d1Z#dBd2d3Z$dCd4d5Z%e d6d7Z&e d8d9Z'e d:d;Z(e dd?Z*dS)D CellRangea 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, ifG)minmax expected_typeiNcCs|dk r6d|kr&t|\}\}}}}nt|\}}}}||_||_||_||_||_||krrd}t|j||d||krd}t|j||ddS)N!z({max_col} must be greater than {min_col})min_colmax_colz({max_row} must be greater than {min_row})min_rowmax_row) rrrrrrtitle ValueErrorformat)selfZ range_stringrrrrrfmtrw/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/openpyxl/openpyxl/worksheet/cell_range.py__init__/szCellRange.__init__cCs|j|j|j|jfS)z2 Vertices of the range as a tuple rrrrrrrrboundsEszCellRange.boundscCsBd}|j|jkr |j|jkr d}|jt|j|jt|j|jdS)z9 Excel-style representation of the range z%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row}r)rrrrrr rrrrrcoordMs  zCellRange.coordc#s>t|j|jdD]&fddt|j|jdDVqdS)z1 Return cell coordinates as rows r csg|] }|fqSrr.0colrowrr dsz"CellRange.rows..N)rangerrrrrrr%rrows^szCellRange.rowsc#s>t|j|jdD]&fddt|j|jdDVqdS)z4 Return cell coordinates as columns r csg|] }|fqSrrr#r&r$rrr'msz"CellRange.cols..N)r(rrrrrrr+rcolsgszCellRange.colscCs8t|tsttt||jr4|j|jkr4tddS)z Check whether comparisons between ranges are possible. Cannot compare ranges from different worksheets Skip if the range passed in has no title. z1Cannot work with ranges from different worksheetsN) isinstancer TypeErrorreprtyperrrotherrrr _check_titleps zCellRange._check_titlecCs&d}|jrd}|j|jj|j|jdS)Nz<{cls} {coord}>z<{cls} {title!r}!{coord}>)clsrr!)rr __class____name__r!r rrr__repr__}szCellRange.__repr__cCs*d}|j}|rd}t|}|j||jdS)Nz{coord}z{title}!{coord})rr!)rr rr!)rrrrrr__str__s zCellRange.__str__cCs|j|j|j|j|j|jdS)Nrrrrr)r5rrrrrrrrr__copy__s  zCellRange.__copy__rcCsh|j|dks|j|dkr,td|||j|7_|j|7_|j|7_|j|7_dS)a{ Shift the focus of the range according to the shift values (*col_shift*, *row_shift*). :type col_shift: int :param col_shift: number of columns to be moved by, can be negative :type row_shift: int :param row_shift: number of rows to be moved by, can be negative :raise: :class:`ValueError` if any row or column index < 1 rz1Invalid shift value: col_shift={0}, row_shift={1}N)rrrrrr)rZ col_shiftZ row_shiftrrrshifts  zCellRange.shiftcCsVz||Wntk r$YdSX|j|jkpT|j|jkpT|j|jkpT|j|jkS)z Test whether the ranges are not equal. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* != *other*. T)r3rrrrrr1rrr__ne__s    zCellRange.__ne__cCs || S)z Test whether the ranges are equal. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* == *other*. )r<r1rrr__eq__szCellRange.__eq__cCs^|||j|jko.|jko.|jkno\|j|jkoX|jkoX|jkSS)z Test whether every cell in this range is also in *other*. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* <= *other*. r3rrrrr1rrrissubsets *(zCellRange.issubsetcCs||o||S)z Test whether *other* contains every cell of this range, and more. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* < *other*. )__le__r<r1rrr__lt__szCellRange.__lt__cCs^|||j|jko.|jko.|jkno\|j|jkoX|jkoX|jkSS)z Test whether every cell in *other* is in this range. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* >= *other* (or *other* in *range*). r>r1rrr issupersets *(zCellRange.issupersetcCs&||}|jdkr|j|_||S)zO Check whether the range contains a particular cell coordinate N)r5rrB)rr!crrrr __contains__s  zCellRange.__contains__cCs||o||S)z Test whether this range contains every cell in *other*, and more. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range :return: ``True`` if *range* > *other*. )__ge__r<r1rrr__gt__szCellRange.__gt__cCsD|||j|jkr ||}}|j|jkpB|j|jkpB|j|jkS)aV 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. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range. :return: ``True`` if the range has no cells in common with other. )r3rrrrrr1rrr isdisjoint s      zCellRange.isdisjointcCsb||rtd||t|j|j}t|j|j}t|j|j}t|j|j}t ||||dS)aN Return a new range with cells common to this range and *other* :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range. :return: the intersecting sheet range. :raise: :class:`ValueError` if the *other* range doesn't intersect with this range. zRange {0} doesn't intersect {0}r) rGrrrrr rrrr rr2rrrrrrr intersection!s zCellRange.intersectioncCsV||t|j|j}t|j|j}t|j|j}t|j|j}t|||||jdS)a 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``. :type other: openpyxl.worksheet.cell_range.CellRange :param other: Other sheet range. :return: a ``CellRange`` that is a superset of this and *other*. r9) r3r rrrrrr rrHrrrunion9s zCellRange.unionccs.|jD]"}|dkrqt||}||fVqdS)zC For use as a dictionary elsewhere in the library. rN) __attrs__getattr)rxvrrr__iter__Os   zCellRange.__iter__cCs<|j|8_|j|8_|j|7_|j|7_dS)a Expand the range by the dimensions provided. :type right: int :param right: expand range to the right by this number of cells :type down: int :param down: expand range down by this number of cells :type left: int :param left: expand range to the left by this number of cells :type up: int :param up: expand range up by this number of cells Nr)rrightZdownleftZuprrrexpandZs zCellRange.expandcCs<|j|7_|j|7_|j|8_|j|8_dS)a Shrink the range by the dimensions provided. :type right: int :param right: shrink range from the right by this number of cells :type down: int :param down: shrink range from the top by this number of cells :type left: int :param left: shrink range from the left by this number of cells :type up: int :param up: shrink range from the bottown by this number of cells Nr)rrPbottomrQtoprrrshrinkms zCellRange.shrinkcCs*|jd|j}|jd|j}||dS)zC Return the size of the range as a dictionary of rows and columns. r )columnsr))rrrr)rr,r)rrrsizeszCellRange.sizecs fddtjjdDS)z=A list of cell coordinates that comprise the top of the rangecsg|]}j|fqSr)rr"rrrr'sz!CellRange.top..r r(rrrrrrrTsz CellRange.topcs fddtjjdDS)z@A list of cell coordinates that comprise the bottom of the rangecsg|]}j|fqSr)rr"rrrr'sz$CellRange.bottom..r rXrrrrrSszCellRange.bottomcs fddtjjdDS)zCA list of cell coordinates that comprise the left-side of the rangecsg|]}|jfqSr)rr*rrrr'sz"CellRange.left..r r(rrrrrrrQszCellRange.leftcs fddtjjdDS)zDA list of cell coordinates that comprise the right-side of the rangecsg|]}|jfqSr)rr*rrrr'sz#CellRange.right..r rYrrrrrPszCellRange.right)NNNNNN)rr)rrrr)rrrr)+r6 __module__ __qualname____doc__rintrrrrrpropertyrr!r)r,r3r7r8r:r;r<r=r?r@rArBrErDrFrGrI__and__rJ__or__rOrRrUrWrTrSrQrPrrrrr sd                  r c@seZdZeedZdddZddZddZd d Z e Z d d Z d dZ ddZ ddZ ddZeZddZddZddZdS)MultiCellRange)rrcCs&t|trdd|D}||_dS)NcSsg|] }t|qSr)r r#rrrrr'sz+MultiCellRange.__init__..)r-strsplitrangesrrfrrrrs zMultiCellRange.__init__cCs|jD]}||krdSqdS)NTFrf)rr!rcrrrrDs zMultiCellRange.__contains__cCs&ddd|jD}d|jj|S)N cSsg|] }t|qSrrdrbrrrr'sz+MultiCellRange.__repr__..z <{0} [{1}]>)joinrfrr5r6rgrrrr7szMultiCellRange.__repr__cCsddd|jD}|S)NricSsg|] }t|qSrrjrbrrrr'sz*MultiCellRange.__str__..)rkrfrgrrrr8szMultiCellRange.__str__cCsJd}t|tr|}|j}||krF|dkr0t|}|j}||||_dS)z4 Add a cell coordinate or CellRange N)r-r r!rfappend)rr!rCrfrrradds  zMultiCellRange.addcCs|||SN)rmrr!rrr__iadd__s zMultiCellRange.__iadd__cCs t|tr||}|j|jkSrn)r-rdr5rfr1rrrr=s  zMultiCellRange.__eq__cCs ||k Srnrr1rrrr<szMultiCellRange.__ne__cCs t|jSrn)boolrfrrrr__bool__szMultiCellRange.__bool__cCs"t|tst|}|j|dSrn)r-r rfremoverorrrrss zMultiCellRange.removeccs|jD] }|VqdSrnrh)rrCrrrrOs zMultiCellRange.__iter__cCs&t}|jD]}|jt|q |Srn)rarfrlr)rnrcrrrr:s zMultiCellRange.__copy__N)r)r6rZr[rr rfrrDr7r8rmrpr=r<rr __nonzero__rsrOr:rrrrras  raN)rZopenpyxl.descriptorsrrrZ!openpyxl.descriptors.serialisablerZopenpyxl.utilsrrr r r rarrrrs