
    ddb*                        d 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 	 ddlmZ n# e$ r d	ZY nw xY wd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*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ dZAd ZBd ZC G d d           ZDd	ed	d!fd"ZEdS )#zRead an xlsx file into Python    )ZipFileZIP_DEFLATED
BadZipfile)exc_info)BytesION)TableDefinition   )KEEP_VBAF)InvalidFileException)ARC_SHARED_STRINGSARC_COREARC_CONTENT_TYPESARC_WORKBOOK	ARC_THEMECOMMENTS_NSSHARED_STRINGSEXTERNAL_LINKXLTMXLTXXLSMXLSX)
MergedCell)CommentSheet   )read_string_table)WorkbookParser)apply_stylesheet)DocumentProperties)ManifestOverride)RelationshipListget_dependentsget_rels_path)ReadOnlyWorksheet)WorksheetReader)
Chartsheet)Table)SpreadsheetDrawing)
fromstring)find_images)z.xlsxz.xlsmz.xltxz.xltmc                 L   t          | d          }|st          j                            |           d                                         }|t
          vrA|dk    rd}n)|dk    rd}n d|dd	                    t
                    }t          |          t          | d
          }|S )a  
    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.
    readz.xlszopenpyxl 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.z.xlsbz|openpyxl does not support binary format .xlsb, please convert this file to .xlsx format if you want to open it with openpyxlzopenpyxl does not support zT file format, please check you can open it with Excel first. Supported formats are: ,r)	hasattrospathsplitextlowerSUPPORTED_FORMATSjoinr   r   )filenameis_file_likefile_formatmsgarchives        5lib/python3.11/site-packages/openpyxl/reader/excel.py_validate_archiver=   C   s     8V,,L ,g&&x004::<<// 	,f$ T< ' 	T2	T 8C{{7:xx@Q7R7R7R	T
 's+++h$$GN    c                 2   t           t          t          t          g}|D ]}|                     |          }|r|c S d | j        D             }|t          |          z  }|r*t          dt          z   |	                                          S t          d          )Nc                     h | ]	}|j         
S  )ContentType).0ps     r<   	<setcomp>z&_find_workbook_part.<locals>.<setcomp>l   s    777!777r>   /z$File contains no valid workbook part)r   r   r   r   findDefaultsetr    r   popIOError)packageworkbook_typesctpartdefaultsworkbook_types         r<   _find_workbook_partrR   d   s    D$-N  ||B 	KKK	 87w777Hs>222M Al*M,=,=,?,?@@@
8
9
99r>   c                   R    e Zd ZdZdeddfdZd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZdS )ExcelReaderzQ
    Read an Excel package and dispatch the contents to the relevant modules
    FTc                     t          |          | _        | j                                        | _        || _        || _        || _        || _        g | _        d S N)	r=   r;   namelistvalid_files	read_onlykeep_vba	data_only
keep_linksshared_strings)selffnrY   rZ   r[   r\   s         r<   __init__zExcelReader.__init__z   sQ    (,,<0022" "$ r>   c                     | j                             t                    }t          |          }t	          j        |          | _        d S rV   )r;   r,   r   r)   r   	from_treerL   )r^   srcroots      r<   read_manifestzExcelReader.read_manifest   s9    l 122#)$//r>   c                     | j                             t                    }|X|j        dd          }| j                            |          5 }t          |          | _        d d d            d S # 1 swxY w Y   d S d S )Nr   )rL   rG   r   PartNamer;   openr   r]   )r^   rN   strings_pathrc   s       r<   read_stringszExcelReader.read_strings   s    \~.. 	=;qrr?L""<11 =S&7&<&<#= = = = = = = = = = = = = = = = = =	= 	=s   A--A14A1c                 P   t          | j                  }t          | j        |j        dd          | j                  | _        | j                                         | j        j        }g |_	        | j
        |_        | j        |_        |j        t          t           fv |_        | j        rdt'          t)                      dt*                    |_        | j        D ]5}|j                            || j                            |                     6| j        r| j        |_        || _        d S )Nr   )r\   a)rR   rL   r   r;   rg   r\   parserparsewb_sheetsr[   
_data_onlyrY   
_read_onlyrB   r   r   templaterZ   r   r   r   vba_archiverX   writestrr,   _archive)r^   wb_partro   names       r<   read_workbookzExcelReader.read_workbook   s   %dl33$T\73CABB3GTXTcddd[^
)dD\9 = 	G$WYY\BBBN( G G''dl.?.?.E.EFFFF> 	',BKr>   c                     t           | j        v rLt          | j                            t                               }t          j        |          | j        _        d S d S rV   )	r   rX   r)   r;   r,   r   rb   ro   
properties)r^   rc   s     r<   read_propertieszExcelReader.read_properties   sW    t'' 	CT\..x8899C!3!=c!B!BDG	C 	Cr>   c                 x    t           | j        v r+| j                            t                     | j        _        d S d S rV   )r   rX   r;   r,   ro   loaded_themer^   s    r<   
read_themezExcelReader.read_theme   s?    (( 	@#'<#4#4Y#?#?DG   	@ 	@r>   c                 `   |j         }t          |          }g }|| j        v rt          | j        |          }| j                            |d          5 }|                                }d d d            n# 1 swxY w Y   t          |          }t          j	        |          }	| j
        |	_        |j        |	_        | j
                            |	           |                    t           j                  }
|
D ]9}t%          | j        |j                   \  }}|D ]}|	                    |           :d S )Nr/   )targetr#   rX   r"   r;   rh   r,   r)   r&   rb   ro   _parentrx   title
_add_sheetrG   r(   	_rel_typer*   	add_chart)r^   sheetrel
sheet_path	rels_pathrelsrc   xmlnodecsdrawingschartsimagescs                 r<   read_chartsheetzExcelReader.read_chartsheet   s`   Z
!*--	(( 	;!$,	::D\z3// 	3((**C	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#!$''W
:299/9:: 	  	 C(szBBNFF    Q 	  	 s   A33A7:A7c           
         d}| j                                         D ]\  }}|j        | j        vrd|j        v r|                     ||           5t          |j                  }t                      }|| j        v rt          | j	        |          }| j
        rRt          | j        |j        |j        | j                  }|j        |_        | j        j                            |           | j	                            |j                  }| j                            |j                  }||_        t-          ||| j        | j                  }|                                 |                    t4                    D ]}	| j	                            |	j                  }
t9          j        t=          |
                    }|j        D ]t\  }}	 |||         _         # tB          $ rT ||         }tE          |tF                    r4tI          j%        |&                    |j'        |j(                             Y oY qw xY w| j        j)        r|j*        r||j*                 j        |_*        nd |_*        |j+        D ]T}| j	                            |          }
t=          |
          }tY          j        |          }|-                    |           U|                    t\          j/                  }|D ]_}ta          | j	        |j                  \  }}|D ]}|1                    ||j2                   |D ]}|3                    ||j2                   `|                    th          j5                  }|D ]w}	|	j6        }| j	                            |          }
t=          |
          }ti          j        |          }| j         j7        |j8                 |_9        |:                    |           x|j        |_        d S )Nz~Cell '{0}':{1} is part of a merged range but has a comment which will be removed because merged cells cannot contain any data.
chartsheet);rm   find_sheetsr   rX   Typer   r#   r!   r"   r;   rY   r$   ro   rx   r]   statesheet_staterp   appendrh   create_sheet_relsr%   r[   bind_allrG   r   r,   r   rb   r)   commentscommentAttributeError
isinstancer   warningswarnformatr   
coordinatert   legacy_drawingtablesr'   	add_tabler(   r   r*   r   anchor	add_imager   rel_typeTargetpivot_cachescacheIdcache	add_pivot)r^   comment_warningr   r   r   r   wsfh	ws_parserr/   rc   comment_sheetrefr   r   tr   tabler   r   r   im	pivot_rel
pivot_pathtreepivots                             r<   read_worksheetszExcelReader.read_worksheets   s    _+1133 C	) C	)JE3z!11 sx' $$UC000%cj11I#%%DD,, ?%dlI>>~ 
%&tw
CJH[\\!&&&r***\&&sz22W))%*55+BD4GXX	""$$$ YY{++ 
% 
%l''11 , 6z# G G$1$: % %LC%*13) % % %sG%a44 %$M/*@*@1<*X*XYYY$H% %%% w" )r'8 )$():$;$B!!$(!% $ $l''** oo,,U####yy!3!=>>H 0 0!,T\3:!F!F . .ALLAH----  0 0BLLRY////0 		/":;;I $ $X
l''
33!#'1$77"k6u}EU####"[BNNGC	) C	)s   GAH4	3H4	c                    |                                   |                                  |                                  |                                  |                                  t          | j        | j                   |                                  | j	        
                                 | j        s| j                                         d S d S rV   )re   rj   ry   r|   r   r   r;   ro   r   rm   assign_namesrY   closer   s    r<   r,   zExcelReader.read  s    tw///  """~ 	!L     	! 	!r>   N)__name__
__module____qualname____doc__r
   r`   re   rj   ry   r|   r   r   r   r,   rA   r>   r<   rT   rT   t   s          ',h!d! ! ! !0 0 0= = =  .C C C@ @ @
     ,E) E) E)P
! 
! 
! 
! 
!r>   rT   Tc                 ^    t          | ||||          }|                                 |j        S )a  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 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.

    )rT   r,   ro   )r7   rY   rZ   r[   r\   readers         r<   load_workbookr      s3    6 9h!:/ /F
KKMMM9r>   )Fr   zipfiler   r   r   sysr   ior   os.pathr1   r   openpyxl.pivot.tabler   testsr
   ImportErroropenpyxl.utils.exceptionsr   openpyxl.xml.constantsr   r   r   r   r   r   r   r   r   r   r   r   openpyxl.cellr   openpyxl.comments.comment_sheetr   stringsr   workbookr   openpyxl.styles.stylesheetr   openpyxl.packaging.corer   openpyxl.packaging.manifestr   r    openpyxl.packaging.relationshipr!   r"   r#   openpyxl.worksheet._read_onlyr$   openpyxl.worksheet._readerr%   openpyxl.chartsheetr&   openpyxl.worksheet.tabler'   $openpyxl.drawing.spreadsheet_drawingr(   openpyxl.xml.functionsr)   r   r*   r5   r=   rR   rT   r   rA   r>   r<   <module>r      s   $ # 6 5 5 5 5 5 5 5 5 5               0 0 0 0 0 0          HHH
 ; : : : : :                            % $ $ $ $ $ 8 8 8 8 8 8 & & & & & & $ $ $ $ $ $ 7 7 7 7 7 7 6 6 6 6 6 6 : : : : : : : :          < ; ; ; ; ; 6 6 6 6 6 6 * * * * * * * * * * * * C C C C C C - - - - - - ! ! ! ! ! ! 9   B: : : i! i! i! i! i! i! i! i!X ',h!d     s   / 99