i7dZddlmZddlmZmZddlmZmZddl Z ddl m Z e j dZ d Zd Zd Ze j d ezd ze jZdZe j deee jZdZdZdZdgeezZeddZdeedDZdZeddZdZ dZ!dZ"dZ#dZ$dZ%dS)zT Collection of utilities used within the package and also available for client code ) lru_cache)chainproduct)ascii_uppercasedigitsN)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})(?=,?)ct|trt|}t|trt|}dt||dzDS)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. c,g|]}t|Sget_column_letter).0xs AC:\PYTHON\_runtimes\venv\Lib\site-packages\openpyxl/utils/cell.py z'get_column_interval..)s! @ @ @Q a @ @ @r) isinstancestrcolumn_index_from_stringrange)startends rget_column_intervalrsd%0(//#s,&s++ @ @%sQw*?*? @ @ @@rct|}|sd|d}t||\}}t |}|sd|d}t|||fS)z;Convert a coordinate string like 'B12' to a tuple ('B', 12)zInvalid cell coordinates ()zThere is no row 0 ()COORD_REmatchr groupsint) coord_stringr msgcolumnrows rcoordinate_from_stringr',s NN< ( (E ,:<:::&s+++,,..KFC c((C ,3L333&s+++ 3;rct|}|st|d|d}|D]\}}|rd|||<|ds|drd}nd}|jdi|S) zDConvert a coordinate to an absolute coordinate string (B12 -> $B$12)z is not a valid coordinate ranger max_colmax_rowz%{min_col}{min_row}:{max_col}{max_row}z{min_col}{min_row}r) ABSOLUTE_REr ValueError groupdictitemsformat)r#mdkvfmts rabsolute_coordinater6:s,''A LLJJJKKK BA 1  q77AaD|#q|#5" 3:????rr))maxsizecbd|cxkrdks$ntd|g}|dkr t|S|rSt|d\}}|dt||s|dz}|dd|Sd|S)a Convert decimal column position to its ASCII (base 26) form. Because column indices are 1-based, strides are actually pow(26, n) + 26 Hence, a correction is applied between pow(26, n) and pow(26, 2) + 26 to prevent and additional column letter being prepended "A" == 1 == pow(26, 0) "Z" == 26 == pow(26, 0) + 26 // decimal equivalent 10 "AA" == 27 == pow(26, 1) + 1 "ZZ" == 702 == pow(26, 2) + 26 // decimal equivalent 100 rifGzInvalid column index {0}rZr))r-r0__decimal_to_alphadivmodinsertjoin)col_idxresult remainders rrrNs  5 3::7CCDDD F||!'** "#GR00 a+I6777 " qLG MM!S ! ! ! " 776??rci|]\}}|| Srr)rposletters r rEosRRR[S&fSRRRr)rr9icvd|d}t|dkrt|d}t|}t |t D]9\}} t |}n#t$rt|wxYw|||zz }:d|cxkrdksnt||S)z Convert ASCII column name (base 26) to decimal with 1-based index Characters represent descending multiples of powers of 26 "AFZ" == 26 * pow(26, 0) + 6 * pow(26, 1) + 1 * pow(26, 2) 'z<' is not a valid column name. Column names are from A to ZZZrigG)lenr-reversedupperzip__powers__alpha_to_decimalKeyError)col error_msgidxrDpowerrCs rrrrsVCUUUI 3xx!||### C 399;;  CS(++  ($V,CC ( ( (Y'' ' ( sU{ s????U????### Js ' A55Bc$d|}t|}|st||\}}}}}|re||f}||f} t || zsKt |rt | r-t | rt |rt||t|}|t|}|t|}n|}|t|}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 range) r0r,r r-r!allanyrr") range_stringr$r1min_colmin_rowsepr*r+colsrowss rrange_boundariesr]s7 3 9 9, G GC,''A oo./hhjj+GWc7G " t   " II "!$ii " II ""$ii " S// !*733g,,*733g,, GWg --rc#Kt|\}}}}t||dz}dt||dzD}|D]tfd|DV dS)[ Get individual addresses for every cell in a range. Yields one row at a time. rc,g|]}t|SrrrrPs rrz#rows_from_range..s! J J Js c " " J J Jrc3DK|]}d|VdSz{0}{1}Nr0)rrPr&s r z"rows_from_range..1>>#HOOC-->>>>>>rNr]rtuple)rWrXrYr*r+r\r[r&s @rrows_from_rangeris *:,)G)G&GWgw 'A+ & &D J JeGWq[.I.I J J JD??>>>>>>>>>>>>>??rc#Kt|\}}}}t||dz}dt||dzD}|D]tfd|DV dS)r_rc34K|]}t|VdS)Nrras rrez"cols_from_range..s+ H Hs c " " H H H H H Hrc3DK|]}d|VdSrcrd)rr&rPs rrez"cols_from_range..rfrNrg)rWrXrYr*r+r\r[rPs @rcols_from_rangerms *:,)G)G&GWgw '!) $ $D H HeGWQY.G.G H H HD??>>>>>>>>>>>>>??rct|D]\}}|tvrn|d|}||d}t|t|fS)zB Convert an Excel style coordinate to (row, column) tuple N) enumeraterr"r) coordinaterRcrPr&s rcoordinate_to_tuplerrshJ''Q ;; E  TcT C STT C s88-c22 22rct|}|td|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:E4quoted notquotedcells) SHEETRANGE_REr r-groupr])rWr1 sheetnamerv boundariess rrange_to_tupler{sv L))AyDEEE!!9QWW[%9%9I GGG  E!%((J j  rcdd|vr|dd}d|}|S)z> Add quotes around sheetnames if they contain spaces. rGz''z'{0}')replacer0)rys rquote_sheetnamer~s; i%%c400  **I r)&__doc__ functoolsr itertoolsrrstringrrre exceptionsr compiler COL_RANGE ROW_RANGE RANGE_EXPRVERBOSEr, SHEET_TITLEr0rwrr'r6listr;rrorNrMrr]rirmrrr{r~rrrrs $$$$$$$$******** 000000 2:7 8 8 (   bjz)3. ;; :  8?? j**  A A A   $TDD111 4@SRIIoq4Q4QRRR  40(.(.(.V ? ? ? ? ? ? 3 3 3 ! ! !r