U
    >Ke                     @   s   d dl Z ddlmZmZ ddlmZ e de jZe dZ	e de jZ
e de jZe d	e jZd
d Zdd Zdd ZdddZdddZdd Zdd Zdd Zdd ZdS )    N   )MAX_ROWMAX_COL)xrangez(\$?)([A-I]?[A-Z])(\$?)(\d+)z\$?(\d+):\$?(\d+)z!\$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])z-\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)z\$?([A-I]?[A-Z]\$?\d+)c                 C   sV   d}d}t t| d ddD ]0}| | }|t|td d | 7 }|d9 }q|d S )z)'A' -> 0, 'Z' -> 25, 'AA' -> 26, etc
    r   r   A   )r   lenord)Zcolnamecolpowerich r   ./tmp/pip-unpacked-wheel-x1drl5t4/xlwt/Utils.pycol_by_name   s    
r   c                 C   s^   t | }|std|  | \}}}}t|}t|}t|d }t| }||||fS )zConvert an Excel cell reference string in A1 notation
    to numeric row/col notation.

    Returns: row, col, row_abs, col_abs

    z$Ill-formed single_cell reference: %sr   )_re_cell_exmatch	Exceptiongroupsboolintr   uppercellmcol_absr   row_absrowr   r   r   cell_to_rowcol   s    
r   c                 C   sF   t | }|std| \}}}}t|d }t| }||fS )zsConvert an Excel cell reference string in A1 notation
    to numeric row/col notation.

    Returns: row, col

    zError in cell formatr   )r   r   r   r   r   r   r   r   r   r   r   cell_to_rowcol2.   s    
r    Fc                 C   s   d|   krt k sn td|  kr.tk s4n t|d }|d }d}|rRd}nd}|r`d}nd}|dkrttd| d }ttd| }|| | | t| d  S )z\Convert numeric row/col notation to an Excel cell reference string in
    A1 notation.

    r   r    $r   r   )r   AssertionErrorr   chrr
   str)r   r   r   r   dr   Zchr1Zchr2r   r   r   rowcol_to_cell@   s    r'   c                 C   s8   | |kst ||kst t| |||d t|||| S )zsConvert two (row,column) pairs
    into a cell range string in A1:B2 notation.

    Returns: cell range string
    :)r#   r'   )row1col1row2col2Zrow1_absZcol1_absZrow2_absZcol2_absr   r   r   rowcol_pair_to_cellrangeX   s    r-   c                 C   s  |   } t| }|rNt|dd }d}t|dd }d}||||fS t| }|rt|d  }d}t|d  }d}||||fS t| }|rt|d\}}t|d\}}||||fS t	| }|rt|d\}}||||fS t
d|  dS )zpConvert cell range string in A1 notation to numeric row/col
    pair.

    Returns: row1, col1, row2, col2

    r   r      r   zUnknown cell reference %sN)r   _re_row_ranger   r   group_re_col_ranger   _re_cell_ranger    _re_cell_refr   )Z	cellrangeresr)   r*   r+   r,   r   r   r   cellrange_to_rowcol_pairg   s2    



r5   c                 C   sh   t | \}}}}|tkr$td|  |tkr<td| tf |t| d> O }|t| d> O }||fS )z5 pack row and column into the required 4 byte format z$Column %s greater than IV in formulaz!Row %s greater than %d in formula      )r   r   r   r   r   )r   r   r   r   r   r   r   r   cell_to_packed_rowcol   s    r8   c                 C   s@   | dks | d dks t | dkr$dS | D ]}|dkr( dS q(dS )Nr!   r   '   Fz[]:\?/* T)r	   )Z
sheet_namecr   r   r   valid_sheet_name   s     r<   c                 C   s(   t | std|  d| dd d S )Nz-attempt to quote an invalid worksheet name %rr9   z'')r<   r   replace)Zunquoted_sheet_namer   r   r   quote_sheet_name   s
    r>   )FF)FFFF)reZ
ExcelMagicr   r   compatr   compile
IGNORECASEr   r/   r1   r2   r3   r   r   r    r'   r-   r5   r8   r<   r>   r   r   r   r   <module>   s(   

       
'