ó
ø`9Sc           @   sF   d  Z  d d l Z d d l Z d „  Z d „  Z d „  Z d „  Z d S(   s8   Additional functions to work with Microsoft Excel files.iÿÿÿÿNc         C   sÇ   t  |  ƒ d k s t ‚ d } xT |  D]L } t | ƒ t d ƒ } d | k oX d k  n sc t ‚ | d | } q% Wx0 t t  |  ƒ d ƒ D] } | d | d 7} qŒ Wt j | ƒ |  k sÃ t ‚ | S(   s¡   Return the zero-based numeric index of an Excel column whose letter
    index is 'columnName'.

    'columnName' has to be a sequence of uppercase latin letters.i    t   Ai   i   (   t   lent   AssertionErrort   ordt   ranget   xlrdt   colname(   t
   columnNamet   indext   chart   digitt   i(    (    s   code\common\utils\excel.pyt   getColumnIndex   s    "c            s€   | t  j k r d Sy t  j |  | ƒ ‰  Wn t  j k
 r@ d SXt ‡  f d †  d	 Dƒ ƒ ra d St j ˆ  d ˆ  d ˆ  d ƒ S(
   sn   Return a 'datetime.date' instance holding the value of an Excel cell or
    'None' if the value is not a date.c         3   s   |  ] } ˆ  | d  k Vq d S(   g        N(    (   t   .0R   (   t	   dateTuple(    s   code\common\utils\excel.pys	   <genexpr>;   s    i   i   i   i    i   i   N(   i   i   i   (   R   t   XL_CELL_DATEt   Nonet   xldate_as_tuplet   XLDateErrort   anyt   datetimet   date(   t	   cellValuet   cellTypet   workBookDateMode(    (   R   s   code\common\utils\excel.pyt   readDate.   s    c            s€   | t  j k r d Sy t  j |  | ƒ ‰  Wn t  j k
 r@ d SXt ‡  f d †  d	 Dƒ ƒ ra d St j ˆ  d ˆ  d ˆ  d ƒ S(
   sn   Return a 'datetime.time' instance holding the value of an Excel cell or
    'None' if the value is not a time.c         3   s   |  ] } ˆ  | d  k Vq d S(   g        N(    (   R   R   (   R   (    s   code\common\utils\excel.pys	   <genexpr>M   s    i    i   i   i   i   i   N(   i    i   i   (   R   R   R   R   R   R   R   t   time(   R   R   R   (    (   R   s   code\common\utils\excel.pyt   readTime@   s    c         C   sG   y t  j |  d t ƒ} Wn t t  j f k
 r6 t SX| | j ƒ  k S(   s   Check if 'filePath' points to a valid Excel file that may be opened for
    reading and contains a worksheet of the given name.t	   on_demand(   R   t   open_workbookt   Truet   IOErrort	   XLRDErrort   Falset   sheet_names(   t   filePatht   worksheetNamet   workBook(    (    s   code\common\utils\excel.pyt   checkWorksheetExistsR   s
    (   t   __doc__R   R   R   R   R   R&   (    (    (    s   code\common\utils\excel.pyt   <module>   s   			