
    fhE0                        d Z ddlmZ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 ddlmZ ddlmZ ddl 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,m-Z- ddl.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? dZ@d ZAd ZB G d d           ZCdedd!dfd"ZDdS )#zRead an xlsx file into Python    )ZipFileZIP_DEFLATED)BytesION)TableDefinition   )KEEP_VBAF)InvalidFileException)ARC_CORE
ARC_CUSTOMARC_CONTENT_TYPESARC_WORKBOOK	ARC_THEMECOMMENTS_NSSHARED_STRINGSXLTMXLTXXLSMXLSX)
MergedCell)CommentSheet   )read_string_tableread_rich_text)WorkbookParser)apply_stylesheet)DocumentProperties)CustomPropertyList)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        L/var/www/histauto/venv/lib/python3.11/site-packages/openpyxl/reader/excel.py_validate_archiver<   B   s     8V,,L ,g&&x004::<<///f$$< ''2 ( 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>k   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_partrQ   c   s    D$-N  ||B 	KKK	 87w777Hs>222M Al*M,=,=,?,?@@@
8
9
99r=   c                   Z    e Zd ZdZdedddfdZ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	rich_textshared_strings)selffnrX   rY   rZ   r[   r\   s          r;   __init__zExcelReader.__init__y   sX    (,,<0022" "$" r=   c                     | j                             t                    }t          |          }t	          j        |          | _        d S rU   )r:   r+   r   r(   r   	from_treerK   )r^   srcroots      r;   read_manifestzExcelReader.read_manifest   s9    l 122#)$//r=   c                    | j                             t                    }t          }| j        rt
          }|T|j        dd          }| j                            |          5 } ||          | _	        d d d            d S # 1 swxY w Y   d S d S )Nr   )
rK   rF   r   r   r\   r   PartNamer:   openr]   )r^   rM   readerstrings_pathrc   s        r;   read_stringszExcelReader.read_strings   s    \~.."> 	$#F>;qrr?L""<11 2S&,fSkk#2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 >s    A>>BB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)rQ   rK   r   r:   rg   r[   parserparsewb_sheetsrZ   
_data_onlyrX   
_read_onlyrA   r   r   templaterY   r   r   r   vba_archiverW   writestrr+   _archive)r^   wb_partrp   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 rU   )	r
   rW   r(   r:   r+   r   rb   rp   
propertiesr^   rc   s     r;   read_propertieszExcelReader.read_properties   sP    t'''T\..x8899C!3!=c!B!BDG ('r=   c                     t           | j        v rLt          | j                            t                               }t          j        |          | j        _        d S d S rU   )	r   rW   r(   r:   r+   r   rb   rp   custom_doc_propsr}   s     r;   read_customzExcelReader.read_custom   sP    )))T\..z::;;C'9'CC'H'HDG$$$ *)r=   c                 x    t           | j        v r+| j                            t                     | j        _        d S d S rU   )r   rW   r:   r+   rp   loaded_theme)r^   s    r;   
read_themezExcelReader.read_theme   s8    (((#'<#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"   rW   r!   r:   rh   r+   r(   r%   rb   rp   _parentry   title
_add_sheetrF   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           
      2   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        | j                  }|                                 |                                 |                    t8                    D ]}	| j	                            |	j                  }
t=          j        tA          |
                    }|j!        D ]t\  }}	 |||         _"        # tF          $ rT ||         }tI          |tJ                    r4tM          j'        |(                    |j)        |j*                             Y oY qw xY w| j        j+        r,|j,        r%|-                    |j,                  j        |_,        nd |_,        |j.        D ]T}| j	                            |          }
tA          |
          }t_          j        |          }|0                    |           U|                    tb          j2                  }|D ]_}tg          | j	        |j                  \  }}|D ]}|4                    ||j5                   |D ]}|6                    ||j5                   `|                    tn          j8                  }| j         j9        }|D ]m}	|	j:        }| j	                            |          }
tA          |
          }to          j        |          }||j;                 |_<        |=                    |           n|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)>rn   find_sheetsr   rW   Typer   r"   r    r!   r:   rX   r#   rp   ry   r]   statesheet_staterq   appendrh   create_sheet_relsr$   rZ   r\   bind_allcloserF   r   r+   r   rb   r(   commentscommentAttributeError
isinstancer   warningswarnformatr   
coordinateru   legacy_drawinggettablesr&   	add_tabler'   r   r)   r   anchor	add_imager   rel_typepivot_cachesTarget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_relr   
pivot_pathtreepivots                              r;   read_worksheetszExcelReader.read_worksheets   s     _+1133 E	) E	)JE3z!1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Y]Yghh	""$$$


 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 )$(HHR->$?$?$F!!$(!% $ $l''** oo,,U####yy!3!=>>H 0 0!,T\3:!F!F . .ALLAH----  0 0BLLRY////0 		/":;;I;3L $ $X
l''
33!#'1$77*5=9U####"[BNNKE	) E	)s   "G00AI	I	c                 T   d}	 |                                   d}|                                  d}|                                  d}|                                  d}|                                  d}|                                  d}t          | j        | j                   d}| 	                                 d	}| j
                                         | j        s| j                                         d S d S # t          $ r&}t          d
| d| j        j         d          |d }~ww xY w)Nzread manifestzread stringszread workbookzread propertieszread custom propertiesz
read themezread stylesheetzread worksheetszassign namesz#Unable to read workbook: could not z from z~.
This is most probably because the workbook source files contain some invalid XML.
Please see the exception for more details.)re   rk   rz   r~   r   r   r   r:   rp   r   rn   assign_namesrX   r   
ValueErrorr6   )r^   actiones      r;   r+   zExcelReader.read  sc    	   #F$F   &F  """-F!FOO&FT\47333&F  """#FK$$&&&> %""$$$$$% % 	 	 	=f = =DLDY = = =  		s   C/C7 7
D'!D""D'N)__name__
__module____qualname____doc__r   r`   re   rk   rz   r~   r   r   r   r   r+   r@   r=   r;   rS   rS   s   s          &+X TU	! 	! 	! 	!0 0 02 2 2  .C C CI I I@ @ @
     ,G) G) G)T    r=   rS   Tc                 `    t          | |||||          }|                                 |j        S )aE  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: preserve 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

    :param rich_text: if set to True openpyxl will preserve any rich text formatting in cells. The default is False
    :type rich_text: 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.

    )rS   r+   rp   )r6   rX   rY   rZ   r[   r\   ri   s          r;   load_workbookr   <  s5    < 9h"J	; ;F
KKMMM9r=   )Er   zipfiler   r   ior   os.pathr0   r   openpyxl.pivot.tabler   testsr   ImportErroropenpyxl.utils.exceptionsr	   openpyxl.xml.constantsr
   r   r   r   r   r   r   r   r   r   r   openpyxl.cellr   openpyxl.comments.comment_sheetr   stringsr   r   workbookr   openpyxl.styles.stylesheetr   openpyxl.packaging.corer   openpyxl.packaging.customr   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)   r4   r<   rQ   rS   r   r@   r=   r;   <module>r      s   $ # * ) ) ) ) ) ) )         0 0 0 0 0 0          HHH ; : : : : :                          % $ $ $ $ $ 8 8 8 8 8 8 6 6 6 6 6 6 6 6 $ $ $ $ $ $ 7 7 7 7 7 7 6 6 6 6 6 6 8 8 8 8 8 8 : : : : : : : :          < ; ; ; ; ; 6 6 6 6 6 6 * * * * * * * * * * * * C C C C C C - - - - - - ! ! ! ! ! ! 9   B: : : F F F F F F F FR ',h!de! ! ! ! ! !s   ' 11