"VfildZddlZddlmZmZddlmZmZmZGdde Z Gdd Z dS) a! This module contains code to translate formulae across cells in a worksheet. The idea is that if A1 has formula "=B1+C1", then translating it to cell A2 results in formula "=B2+C2". The algorithm relies on the formula tokenizer to identify the parts of the formula that need to change. N) TokenizerToken)coordinate_to_tuplecolumn_index_from_stringget_column_letterceZdZdZdS)TranslatorErrora Raised when a formula can't be translated across cells. This error arises when a formula's references would be translated outside the worksheet's bounds on the top or left. Excel represents these situations with a #REF! literal error. E.g., if the formula at B2 is '=A1', attempting to translate the formula to B1 raises TranslatorError, since there's no cell above A1. Similarly, translating the same formula from B2 to A2 raises TranslatorError, since there's no cell to the left of A1. N)__name__ __module__ __qualname____doc__Ic:\PYTHON\DbComparer\venv\Lib\site-packages\openpyxl/formula/translate.pyr r s    rr ceZdZdZdZdZejdZejdZ ejdZ e dZ e dZ e d Zed Zdd Zd S) Translatora5 Modifies a formula so that it can be translated from one cell to another. `formula`: The str string to translate. Must include the leading '=' character. `origin`: The cell address (in A1 notation) where this formula was defined (excluding the worksheet name). cft|\|_|_t||_dSN)rrowcolr tokenizer)selfformulaorigins r__init__zTranslator.__init__-s-188$("7++rc|jjS)z6Returns a list with the tokens comprising the formula.)ritems)rs r get_tokenszTranslator.get_tokens4s ~##rz*(\$?[1-9][0-9]{0,6}):(\$?[1-9][0-9]{0,6})$z&(\$?[A-Za-z]{1,3}):(\$?[A-Za-z]{1,3})$z'(\$?[A-Za-z]{1,3})(\$?[1-9][0-9]{0,6})$c|dr|St||z}|dkrtdt|S)zL Translate a range row-snippet by the given number of rows. $rFormula out of range) startswithintr str)row_strrdeltanew_rows r translate_rowzTranslator.translate_row<sS   c " " N'llV+G!||%&<===w<< rc|dr|S tt||zS#t$rt dwxYw)zN Translate a range col-snippet by the given number of columns r!r")r#rr ValueErrorr )col_strcdeltas r translate_colzTranslator.translate_colIss   c " " >N >(,W55>@@@ > > >%&<=== >s 8AcRd|vr |dd\}}|dz|fSd|fS)zCSplits out the worksheet reference, if any, from a range reference.!r)rsplit) range_strsheets r strip_ws_namezTranslator.strip_ws_nameWsB )  (//Q77 E93; ) )9}rcn|\}}j|}|Y||dzdz|dzSj|}|Y||dzdz|dzSd|vr9|dfd|dDzSj |}||S||dz|dzS)aV Translate an A1-style range reference to the destination cell. `rdelta`: the row offset to add to the range `cdelta`: the column offset to add to the range `range_str`: an A1-style reference to a range. Potentially includes the worksheet reference. Could also be a named range. Nr:c3FK|]}|VdSr)translate_range).0piecer-clsr's r z-Translator.translate_range..sI&3&3##E66::&3&3&3&3&3&3r) r5 ROW_RANGE_REmatchr)group COL_RANGE_REr.joinsplit CELL_REF_RE)r=r3r'r-ws_partr@s` `` rr:zTranslator.translate_rangees!..y99 &&y11  c// AGGG#M'' A??@ A &&y11  c// AGGG#M'' A??@ A )   SXX&3&3&3&3&3&3&__S11&3&3&3333 3%%i00 = #++EKKNNFCCC##EKKNNF;;< =rNrc|}|sdS|djtjkr |djSdg}|r&t |\}}||jz }||jz }|D]v}|jtjkrE|j tj kr0| | |j||\| |jwd |S)z Convert the formula into A1 notation, or as row and column coordinates The formula is converted into A1 assuming it is assigned to the cell whose address is `dest` (no worksheet name). r1r=)rtyperLITERALvaluerrrOPERANDsubtypeRANGEappendr:rC) rdest row_delta col_deltatokensoutrrtokens rtranslate_formulazTranslator.translate_formulas"" #2 AY^u} , ,!9? "e  '*400HCdhIdhI ( (E em++MU[00 4// Y09;;<<<< 5;''''wws||r)Nrr)r r r rrrrecompiler?rBrE staticmethodr)r.r5 classmethodr:rVrrrrr!s,,,$$$2:KLLL2:GHHL"*GHHK   \   > >\ >  \  = =[ =Drr) rrWrrropenpyxl.utilsrrr Exceptionr rrrrr]s ''''''''     i   EEEEEEEEEEr