o
    ä›e  ã                   @   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 ]}| | }|t|ƒtdƒ d | 7 }|d9 }q|d S )z)'A' -> 0, 'Z' -> 25, 'AA' -> 26, etc
    r   r   éÿÿÿÿÚAé   )r   ÚlenÚord)ÚcolnameÚcolÚpowerÚiÚch© r   ú=/var/www/html/venv/lib/python3.10/site-packages/xlwt/Utils.pyÚcol_by_name   s   
r   c                 C   s^   t  | ¡}|std|  ƒ‚| ¡ \}}}}t|ƒ}t|ƒ}t|ƒd }t| ¡ ƒ}||||fS )z…Convert 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J ‚ J ‚d|  krtk sJ ‚ J ‚|d }|d }d}|r+d}nd}|r2d}nd}|dkrBt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   r   Úchrr
   Ústr)r   r   r   r   Údr   Úchr1Úchr2r   r   r   Úrowcol_to_cell@   s   r)   c                 C   s8   | |ksJ ‚||ksJ ‚t | |||ƒd t ||||ƒ S )zsConvert two (row,column) pairs
    into a cell range string in A1:B2 notation.

    Returns: cell range string
    ú:)r)   )Úrow1Úcol1Úrow2Úcol2Úrow1_absÚcol1_absÚrow2_absÚcol2_absr   r   r   Úrowcol_pair_to_cellrangeX   s   ÿþÿr3   c                 C   s
  |   ¡ } t | ¡}|r't| d¡ƒd }d}t| d¡ƒd }d}||||fS t | ¡}|rJt| d¡  ¡ ƒ}d}t| d¡  ¡ ƒ}d}||||fS t | ¡}|rit| d¡ƒ\}}t| d¡ƒ\}}||||fS t	 | ¡}|rt| d¡ƒ\}}||||fS t
d|  ƒ‚)zpConvert cell range string in A1 notation to numeric row/col
    pair.

    Returns: row1, col1, row2, col2

    r   r   é   r   zUnknown cell reference %s)r   Ú_re_row_ranger   r   ÚgroupÚ_re_col_ranger   Ú_re_cell_ranger!   Ú_re_cell_refr   )Ú	cellrangeÚresr+   r,   r-   r.   r   r   r   Úcellrange_to_rowcol_pairg   s2   



r<   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   r?   c                 C   s@   | dks| d dkst | ƒdkrdS | D ]	}|dv r dS qdS )Nr"   r   ú'é   Fz[]:\?/* T)r	   )Ú
sheet_nameÚcr   r   r   Úvalid_sheet_name›   s    ÿrD   c                 C   s(   t | ƒs
td|  ƒ‚d|  dd¡ d S )Nz-attempt to quote an invalid worksheet name %rr@   z'')rD   r   Úreplace)Úunquoted_sheet_namer   r   r   Úquote_sheet_name£   s
   ÿrG   )FF)FFFF)ÚreÚ
ExcelMagicr   r   Úcompatr   ÚcompileÚ
IGNORECASEr   r5   r7   r8   r9   r   r    r!   r)   r3   r<   r?   rD   rG   r   r   r   r   Ú<module>   s$   


ÿ'