U o^<@sdZddlZddlmZedZdZdZdZed ed ej Z d Z ed e eej Z d dZddZddZddZiZiZeddD]ZeeZeee<eee<qddZddZddZddZddZd d!Zd"d#Zd$d%ZdS)&zT Collection of utilities used within the package and also available for client code N)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).0xrrm/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/openpyxl/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|}|std||d}|D]\}}|r.d|||<q.|dsZ|dr`d}nd}|jf|S)zDConvert a coordinate to an absolute coordinate string (B12 -> $B$12)z#{0} is not a valid coordinate rangez${0}max_colmax_rowz%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row}) ABSOLUTE_REr ValueErrorformat groupdictitems)rmdkvfmtrrr absolute_coordinate7s  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 r6igGcCs2z t|WStk r,td|YnXdS)z?Convert a column index into a column letter (3 -> 'C') r,N)_STRING_COL_CACHEKeyErrorr"r#)idxrrr ris rcCs6zt|WStk r0td|YnXdS)z@Convert a column name into a numerical index ('A' -> 1) z{0} is not a valid column nameN)_COL_STRING_CACHEupperr8r"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_rowseprr colsrowsrrr range_boundaries~s<     rDc#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#rFrrr sz"rows_from_range..NrDrtupler>r?r@rr rCrBrrJr rows_from_ranges rOc#s\t|\}}}}t||d}ddt||dD}|D]tfdd|DVq:dS)rErcss|]}t|VqdS)NrrFrrr rKsz"cols_from_range..c3s|]}d|VqdSrHrI)r rrGrr rKsNrLrNrrPr cols_from_ranges rQcCs*t|}|dd\}}t|t|fS)zA Convert an Excel style coordinate to (row, colum) tuple r)rsplitrr:)Z coordinaterrGrrrr coordinate_to_tuples rTcCsHt|}|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"grouprD)r>r& sheetnamerVZ boundariesrrr range_to_tuples  rZcCs"d|kr|dd}d|}|S)z> Add quotes around sheetnames if they contain spaces. 'z''z'{0}')replacer#)rYrrr quote_sheetnames  r])__doc__re exceptionsrcompilerZ COL_RANGEZ ROW_RANGEZ RANGE_EXPRVERBOSEr!Z SHEET_TITLEr#rWrrr+r6r:r7rirGrrrDrOrQrTrZr]rrrr s@     +