U Dx`@sdZddlZddlmZddlmZedZdZdZ d Z ed e d ej Z d Z ed e e ej ZddZddZddZddZiZiZeddD]ZeeZeee<eee<qddZddZddZddZdd Zd!d"Zd#d$Zd%d&Z dS)'zT Collection of utilities used within the package and also available for client code N)digits)CellCoordinatesExceptionz^[$]?([A-Za-z]{1,3})[$]?(\d+)$z[A-Z]{1,3}:[A-Z]{1,3}:z\d+:\d+:zq [$]?(?P[A-Za-z]{1,3})? [$]?(?P\d+)? (:[$]?(?P[A-Za-z]{1,3})? [$]?(?P\d+)?)? ^$z7 (('(?P([^']|'')*)')|(?P[^'^ ^!]*))!z{0}(?P{1})(?=,?)cCs<t|trt|}t|tr$t|}ddt||dDS)z Given the start and end columns, return all the columns in the series. The start and end columns can be either column letters or 1-based indexes. cSsg|] }t|qSget_column_letter).0xrr:/tmp/pip-target-zr53vnty/lib/python/openpyxl/utils/cell.py 'sz'get_column_interval..r) isinstancestrcolumn_index_from_stringrange)startendrrr get_column_intervals   rcCsVt|}|s"d|d}t||\}}t|}|sNd|d}t|||fS)z;Convert a coordinate string like 'B12' to a tuple ('B', 12)zInvalid cell coordinates ()zThere is no row 0 ()COORD_REmatchrgroupsint) coord_stringrmsgcolumnrowrrr coordinate_from_string*s    rcCspt|}|st|d|d}|D]\}}|r.d|||<q.|dsZ|dr`d}nd}|jf|S)zDConvert a coordinate to an absolute coordinate string (B12 -> $B$12)z is not a valid coordinate rangermax_colmax_rowz%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row}) ABSOLUTE_REr ValueError groupdictitemsformat)rmdkvfmtrrr absolute_coordinate8s  r,cCstd|krdks$ntd|g}|dkrft|d\}}|dkrRd}|d8}|t|dq(dt|S)zConvert a column number into a column letter (3 -> 'C') Right shift the column col_idx by 26 to find column letters in reverse order. These numbers are 1-based, and can be converted to ASCII ordinals by adding 64. rifGInvalid column index {0}r@r)r#r&divmodappendchrjoinreversed)Zcol_idxletters remainderrrr _get_column_letterJs r7igGcCs2z t|WStk r,td|YnXdS)z?Convert a column index into a column letter (3 -> 'C') r-N)_STRING_COL_CACHEKeyErrorr#r&)idxrrr r is r cCs6zt|WStk r0td|YnXdS)z@Convert a column name into a numerical index ('A' -> 1) z{0} is not a valid column nameN)_COL_STRING_CACHEupperr9r#r&)Zstr_colrrr rssrc Csd|}t|}|s t||\}}}}}|rz||f}||f} t|| szt|rbt| rzt| rrt|rzt||dk rt|}|dk rt|}|dk rt|}n|}|dk rt|}n|}||||fS)z Convert a range string into a tuple of boundaries: (min_col, min_row, max_col, max_row) Cell coordinates will be converted into a range with the cell at both end z&{0} is not a valid coordinate or rangeN) r&r"rr#rallanyrr) range_stringrr'min_colmin_rowsepr r!colsrowsrrr range_boundaries~s<     rEc#s\t|\}}}}t||d}ddt||dD}|D]tfdd|DVq:dS)[ Get individual addresses for every cell in a range. Yields one row at a time. rcSsg|] }t|qSrrr colrrr r sz#rows_from_range..c3s|]}d|VqdSz{0}{1}Nr&rGrrr sz"rows_from_range..NrErtupler?r@rAr r!rDrCrrKr rows_from_ranges rPc#s\t|\}}}}t||d}ddt||dD}|D]tfdd|DVq:dS)rFrcss|]}t|VqdS)NrrGrrr rLsz"cols_from_range..c3s|]}d|VqdSrIrJ)r rrHrr rLsNrMrOrrQr cols_from_ranges rRcCsJt|D]\}}|tkrqq|d|}||d}t|t|fS)zA Convert an Excel style coordinate to (row, colum) tuple N) enumeraterr<rr;)Z coordinater:crHrrrr coordinate_to_tuples  rUcCsHt|}|dkrtd|dp,|d}|d}t|}||fS)zc Convert a worksheet range to the sheetname and maximum and minimum coordinate indices Nz)Value must be of the form sheetname!A1:E4quotedZ notquotedcells) SHEETRANGE_RErr#grouprE)r?r' sheetnamerWZ boundariesrrr range_to_tuples  r[cCs"d|kr|dd}d|}|S)z> Add quotes around sheetnames if they contain spaces. 'z''z'{0}')replacer&)rZrrr quote_sheetnames  r^)!__doc__restringr exceptionsrcompilerZ COL_RANGEZ ROW_RANGEZ RANGE_EXPRVERBOSEr"Z SHEET_TITLEr&rXrrr,r7r;r8rirHr rrErPrRrUr[r^rrrr sB      +