
]c           @@  s`  d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 Z d  d l Z d  d l m Z m Z d  d l m Z y d d	 l m Z Wn e k
 r e Z n Xd  d
 l m Z d  d l m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ d  d l% m& Z& d  d l' m( Z( d d l) m* Z* d d l+ m, Z, d  d l- m. Z. d  d l/ m0 Z0 d  d l1 m2 Z2 m3 Z3 d  d l4 m5 Z5 m6 Z6 m7 Z7 d  d l8 m9 Z9 d  d l: m; Z; d  d l< m= Z= d  d l> m? Z? d  d l@ mA ZA d  d lB mC ZC d d lD mE ZE d% ZF d    ZG d!   ZH d" d& d#     YZI e e e eJ d$  ZK d S('   i    (   t   absolute_import(   t   ZipFilet   ZIP_DEFLATEDt
   BadZipfile(   t   exc_info(   t   BytesION(   t   unicodet   file(   t   TableDefinitioni   (   t   KEEP_VBA(   t   InvalidFileException(   t   ARC_SHARED_STRINGSt   ARC_COREt   ARC_CONTENT_TYPESt   ARC_WORKBOOKt	   ARC_THEMEt   COMMENTS_NSt   SHARED_STRINGSt   EXTERNAL_LINKt   XLTMt   XLTXt   XLSMt   XLSX(   t
   MergedCell(   t   CommentSheeti   (   t   read_string_table(   t   WorkbookParser(   t   apply_stylesheet(   t   DocumentProperties(   t   Manifestt   Override(   t   RelationshipListt   get_dependentst   get_rels_path(   t   ReadOnlyWorksheet(   t   WorksheetReader(   t
   Chartsheet(   t   Table(   t   SpreadsheetDrawing(   t
   fromstring(   t   find_imagess   .xlsxs   .xlsms   .xltxs   .xltmc         C@  s   t  |  d  } | s t j j |   d j   } | t k r | d k rR d } n. | d k rg d } n d | d j t  f } t |   q n  t |  d	  } | S(
   s  
    Does a first check whether filename is a string or a file-like
    object. If it is a string representing a filename, a check is done
    for supported formats by checking the given file-extension. If the
    file-extension is not in SUPPORTED_FORMATS an InvalidFileException
    will raised. Otherwise the filename (resp. file-like object) will
    forwarded to zipfile.ZipFile returning a ZipFile-Instance.
    t   readis   .xlss   openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.s   .xlsbs|   openpyxl does not support binary format .xlsb, please convert this file to .xlsx format if you want to open it with openpyxlsr   openpyxl does not support %s file format, please check you can open it with Excel first. Supported formats are: %st   ,t   r(	   t   hasattrt   ost   patht   splitextt   lowert   SUPPORTED_FORMATSt   joinR
   R   (   t   filenamet   is_file_liket   file_formatt   msgt   archive(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   _validate_archiveE   s    			c         C@  s   t  t t t g } x' | D] } |  j |  } | r | Sq Wt d   |  j D  } | t |  @} | r t d t | j	    St
 d   d  S(   Nc         s@  s   |  ] } | j  Vq d  S(   N(   t   ContentType(   t   .0t   p(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pys	   <genexpr>n   s    t   /s$   File contains no valid workbook part(   R   R   R   R   t   findt   sett   DefaultR   R   t   popt   IOError(   t   packaget   workbook_typest   ctt   partt   defaultst   workbook_type(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   _find_workbook_partf   s    t   ExcelReaderc           B@  sk   e  Z d  Z e e e e d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z RS(
   sQ   
    Read an Excel package and dispatch the contents to the relevant modules
    c         C@  sR   t  |  |  _ |  j j   |  _ | |  _ | |  _ | |  _ | |  _ g  |  _ d  S(   N(	   R8   R7   t   namelistt   valid_filest	   read_onlyt   keep_vbat	   data_onlyt
   keep_linkst   shared_strings(   t   selft   fnRL   RM   RN   RO   (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   __init__|   s    				c         C@  s4   |  j  j t  } t |  } t j |  |  _ d  S(   N(   R7   R)   R   R'   R   t	   from_treeRB   (   RQ   t   srct   root(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_manifest   s    c         C@  s\   |  j  j t  } | d  k	 rX | j d } |  j j |   } t |  |  _ Wd  QXn  d  S(   Ni   (	   RB   R=   R   t   Nonet   PartNameR7   t   openR   RP   (   RQ   RD   t   strings_pathRU   (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_strings   s
    c         C@  s  t  |  j  } t |  j | j d d |  j |  _ |  j j   |  j j } g  | _	 |  j
 | _ |  j | _ | j t t f k | _ |  j r t t   d t  | _ x3 |  j D]% } | j j | |  j j |   q Wn  |  j r |  j | _ n  | |  _ d  S(   Ni   RO   t   a(   RH   RB   R   R7   RY   RO   t   parsert   parset   wbt   _sheetsRN   t
   _data_onlyRL   t
   _read_onlyR9   R   R   t   templateRM   R   R   R   t   vba_archiveRK   t   writestrR)   t   _archive(   RQ   t   wb_partR`   t   name(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_workbook   s    %		&	c         C@  sC   t  |  j k r? t |  j j t    } t j |  |  j _ n  d  S(   N(	   R   RK   R'   R7   R)   R   RT   R`   t
   properties(   RQ   RU   (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_properties   s    c         C@  s.   t  |  j k r* |  j j t   |  j _ n  d  S(   N(   R   RK   R7   R)   R`   t   loaded_theme(   RQ   (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt
   read_theme   s    c         C@  s  | j  } t |  } g  } | |  j k r? t |  j |  } n  |  j j | d   } | j   } Wd  QXt |  } t j	 |  }	 |  j
 |	 _ | j |	 _ |  j
 j |	  | j t j  }
 xG |
 D]? } t |  j | j   \ } } x | D] } |	 j |  q Wq Wd  S(   NR+   (   t   targetR!   RK   R    R7   RZ   R)   R'   R$   RT   R`   t   _parentRi   t   titlet
   _add_sheetR=   R&   t	   _rel_typeR(   t	   add_chart(   RQ   t   sheett   relt
   sheet_patht	   rels_patht   relsRU   t   xmlt   nodet   cst   drawingst   chartst   imagest   c(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_chartsheet   s"    	c         C@  s  d } xy|  j  j   D]h\ } } | j |  j k r: q n  d | j k r_ |  j | |  q n  t | j  } t   } | |  j k r t |  j	 |  } n  |  j
 r t |  j | j | j |  j  } |  j j j |  q nX |  j	 j | j  } |  j j | j  } | | _ t | | |  j |  j  } | j   x | j t  D] }	 |  j	 j |	 j  }
 t j t |
   } xz | j D]o \ } } y | | | _ Wqt k
 r| | } t  | t!  rt" j# | j$ | j% | j&   qqqXqWqFW|  j j' r"| j( r"| | j( j | _( n  xK | j) D]@ } |  j	 j |  }
 t |
  } t* j |  } | j+ |  q,W| j t, j-  } xq | D]i } t. |  j	 | j  \ } } x! | D] } | j/ | | j0  qWx! | D] } | j1 | | j0  qWqW| j t2 j3  } xg | D]_ }	 |	 j4 } |  j	 j |  }
 t |
  } t2 j |  } |  j  j5 | j6 | _7 | j8 |  qW| j9 | _: q Wd  S(   Ns~   Cell '{0}':{1} is part of a merged range but has a comment which will be removed because merged cells cannot contain any data.t
   chartsheet(;   R^   t   find_sheetsRo   RK   t   TypeR   R!   R   R    R7   RL   R"   R`   Ri   RP   Ra   t   appendRZ   t   create_sheett   _relsR#   RN   t   bind_allR=   R   R)   R   RT   R'   t   commentst   commentt   AttributeErrort
   isinstanceR   t   warningst   warnt   formatRq   t
   coordinateRe   t   legacy_drawingt   tablesR%   t	   add_tableR&   Rs   R(   Rt   t   anchort	   add_imageR   t   rel_typet   Targett   pivot_cachest   cacheIdt   cachet	   add_pivott   statet   sheet_state(   RQ   t   comment_warningRu   Rv   Rx   Ry   t   wst   fht	   ws_parserR+   RU   t   comment_sheett   refR   R   t   tRz   t   tableR}   R~   R   t   imt	   pivot_relt
   pivot_patht   treet   pivot(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   read_worksheets   sl    		!	

	c         C@  sy   |  j    |  j   |  j   |  j   |  j   t |  j |  j  |  j   |  j	 j
   |  j su |  j j   n  d  S(   N(   RW   R\   Rj   Rl   Rn   R   R7   R`   R   R^   t   assign_namesRL   t   close(   RQ   (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyR)     s    





	(   t   __name__t
   __module__t   __doc__t   FalseR	   t   TrueRS   RW   R\   Rj   Rl   Rn   R   R   R)   (    (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyRI   v   s   
							Ec         C@  s)   t  |  | | | |  } | j   | j S(   s#  Open the given filename and return the workbook

    :param filename: the path to open or a file-like object
    :type filename: string or a file-like object open in binary mode c.f., :class:`zipfile.ZipFile`

    :param read_only: optimised for reading, content cannot be edited
    :type read_only: bool

    :param keep_vba: preseve vba content (this does NOT mean you can use it)
    :type keep_vba: bool

    :param guess_types: guess cell content type and do not read it from the file
    :type guess_types: bool

    :param data_only: controls whether cells with formulae have either the formula (default) or the value stored the last time Excel read the sheet
    :type data_only: bool

    :param keep_links: whether links to external workbooks should be preserved. The default is True
    :type keep_links: bool

    :rtype: :class:`openpyxl.workbook.Workbook`

    .. note::

        When using lazy load, all worksheets will be :class:`openpyxl.worksheet.iter_worksheet.IterableWorksheet`
        and the returned workbook will be read-only.

    (   RI   R)   R`   (   R3   RL   RM   RN   RO   t   reader(    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   load_workbook  s    
(   s   .xlsxs   .xlsms   .xltxs   .xltm(    (L   t
   __future__R    t   zipfileR   R   R   t   sysR   t   ioR   t   os.pathR-   R   t   openpyxl.compatR   R   t   openpyxl.pivot.tableR   t   testsR	   t   ImportErrorR   t   openpyxl.utils.exceptionsR
   t   openpyxl.xml.constantsR   R   R   R   R   R   R   R   R   R   R   R   t   openpyxl.cellR   t   openpyxl.comments.comment_sheetR   t   stringsR   t   workbookR   t   openpyxl.styles.stylesheetR   t   openpyxl.packaging.coreR   t   openpyxl.packaging.manifestR   R   t   openpyxl.packaging.relationshipR   R    R!   t   openpyxl.worksheet._read_onlyR"   t   openpyxl.worksheet._readerR#   t   openpyxl.chartsheetR$   t   openpyxl.worksheet.tableR%   t$   openpyxl.drawing.spreadsheet_drawingR&   t   openpyxl.xml.functionsR'   R}   R(   R1   R8   RH   RI   R   R   (    (    (    s4   lib/python2.7/site-packages/openpyxl/reader/excel.pyt   <module>   sD   
R	!	