ó
0Ó›Yc           @   sü   d  d l  Z  d d l m Z m Z d d l m Z e  j d e  j ƒ Z e  j d ƒ Z	 e  j d e  j ƒ Z
 e  j d e  j ƒ Z e  j d	 e  j ƒ Z d
 „  Z d „  Z d „  Z e e d „ Z e e e e d „ Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿNi   (   t   MAX_ROWt   MAX_COL(   t   xranges   (\$?)([A-I]?[A-Z])(\$?)(\d+)s   \$?(\d+):\$?(\d+)s!   \$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])s-   \$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)s   \$?([A-I]?[A-Z]\$?\d+)c         C   sq   d } d } xZ t  t |  ƒ d d d ƒ D]< } |  | } | t | ƒ t d ƒ d | 7} | d 9} q) W| d S(   s)   'A' -> 0, 'Z' -> 25, 'AA' -> 26, etc
    i    i   iÿÿÿÿt   Ai   (   R   t   lent   ord(   t   colnamet   colt   powert   it   ch(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   col_by_name   s    #
"c         C   sŠ   t  j |  ƒ } | s( t d |  ƒ ‚ n  | j ƒ  \ } } } } t | ƒ } t | ƒ } t | ƒ d } t | j ƒ  ƒ } | | | | f S(   s…   Convert an Excel cell reference string in A1 notation
    to numeric row/col notation.

    Returns: row, col, row_abs, col_abs

    s$   Ill-formed single_cell reference: %si   (   t   _re_cell_ext   matcht	   Exceptiont   groupst   boolt   intR   t   upper(   t   cellt   mt   col_absR   t   row_abst   row(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   cell_to_rowcol   s    c         C   sh   t  j |  ƒ } | s$ t d ƒ ‚ n  | j ƒ  \ } } } } t | ƒ d } t | j ƒ  ƒ } | | f S(   ss   Convert an Excel cell reference string in A1 notation
    to numeric row/col notation.

    Returns: row, col

    s   Error in cell formati   (   R   R   R   R   R   R   R   (   R   R   R   R   R   R   (    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   cell_to_rowcol2.   s    c         C   så   d |  k o t  k  n s" t ‚ d | k o9 t k  n sD t ‚ | d } | d } d } | rm d } n d } | r‚ d } n d } | d k r± t t d ƒ | d ƒ } n  t t d ƒ | ƒ } | | | | t |  d ƒ S(   s\   Convert numeric row/col notation to an Excel cell reference string in
    A1 notation.

    i    i   t    t   $R   i   (   R    t   AssertionErrorR   t   chrR   t   str(   R   R   R   R   t   dR   t   chr1t   chr2(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   rowcol_to_cell@   s    ""

		c         C   sN   |  | k s t  ‚ | | k s$ t  ‚ t |  | | | ƒ d t | | | | ƒ S(   ss   Convert two (row,column) pairs
    into a cell range string in A1:B2 notation.

    Returns: cell range string
    t   :(   R   R"   (   t   row1t   col1t   row2t   col2t   row1_abst   col1_abst   row2_abst   col2_abs(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   rowcol_pair_to_cellrangeX   s    c         C   s…  |  j  ƒ  }  t j |  ƒ } | ro t | j d ƒ ƒ d } d } t | j d ƒ ƒ d } d } | | | | f St j |  ƒ } | rÖ t | j d ƒ j  ƒ  ƒ } d } t | j d ƒ j  ƒ  ƒ } d } | | | | f St j |  ƒ } | r1t | j d ƒ ƒ \ } } t | j d ƒ ƒ \ } } | | | | f St	 j |  ƒ } | rqt | j d ƒ ƒ \ } } | | | | f St
 d |  ƒ ‚ d S(   sp   Convert cell range string in A1 notation to numeric row/col
    pair.

    Returns: row1, col1, row2, col2

    i   i    i   iÿÿÿÿs   Unknown cell reference %sN(   R   t   _re_row_rangeR   R   t   groupt   _re_col_rangeR   t   _re_cell_rangeR   t   _re_cell_refR   (   t	   cellranget   resR$   R%   R&   R'   (    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   cellrange_to_rowcol_pairg   s2    c         C   s   t  |  ƒ \ } } } } | t k r7 t d |  ƒ ‚ n  | t k r\ t d |  t f ƒ ‚ n  | t | ƒ d >O} | t | ƒ d >O} | | f S(   s5    pack row and column into the required 4 byte format s$   Column %s greater than IV in formulas!   Row %s greater than %d in formulai   i   (   R   R   R   R    R   (   R   R   R   R   R   (    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   cell_to_packed_rowcolŽ   s    c         C   sW   |  d k s. |  d d k s. t  |  ƒ d k r2 t Sx |  D] } | d k r9 t Sq9 Wt S(   Nu    i    u   'i   u   []:\?/* (   R   t   Falset   True(   t
   sheet_namet   c(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   valid_sheet_name›   s    .c         C   s7   t  |  ƒ s t d |  ƒ ‚ n  d |  j d d ƒ d S(   Ns-   attempt to quote an invalid worksheet name %ru   'u   ''(   R:   R   t   replace(   t   unquoted_sheet_name(    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   quote_sheet_name£   s    (   t   ret
   ExcelMagicR    R   t   compatR   t   compilet
   IGNORECASER   R-   R/   R0   R1   R   R   R   R6   R"   R,   R4   R5   R:   R=   (    (    (    s)   lib/python2.7/site-packages/xlwt/Utils.pyt   <module>   s    				'		