
    MwgE0                        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 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"ZDy# e$ r dZY w xY w)#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                 >   t        | d      }|st        j                  j                  |       d   j	                         }|t
        vrJ|dk(  rd}t        |      |dk(  rd}t        |      d|dd	j                  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/horilla/myenv/lib/python3.12/site-packages/openpyxl/reader/excel.py_validate_archiver<   B   s     8V,Lgg&&x04::<//f$< 's++ '2 's++ ( 8C7:xx@Q7R	T
 's++h$GN    c                 2   t         t        t        t        g}|D ]  }| j	                  |      }|s|c S  | j
                  D ch c]  }|j                   }}|t        |      z  }|r!t        dt        z   |j                               S t        d      c c}w )N/z$File contains no valid workbook part)r   r   r   r   findDefaultContentTypesetr   r   popIOError)packageworkbook_typesctpartpdefaultsworkbook_types          r;   _find_workbook_partrM   c   s    D$-N ||BK (/7!7H7s>22Ml*M,=,=,?@@
8
99 8s   Bc                   X    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y)ExcelReaderzQ
    Read an Excel package and dispatch the contents to the relevant modules
    FTc                     t        |      | _        | j                  j                         | _        || _        || _        || _        || _        || _        g | _	        y N)
r<   r:   namelistvalid_files	read_onlykeep_vba	data_only
keep_links	rich_textshared_strings)selffnrT   rU   rV   rW   rX   s          r;   __init__zExcelReader.__init__y   sN    (,<<002" "$" r=   c                     | j                   j                  t              }t        |      }t	        j
                  |      | _        y rQ   )r:   r+   r   r(   r   	from_treerF   )rZ   srcroots      r;   read_manifestzExcelReader.read_manifest   s2    ll 12#))$/r=   c                    | j                   j                  t              }t        }| j                  rt
        }|A|j                  dd  }| j                  j                  |      5 } ||      | _	        d d d        y y # 1 sw Y   y xY w)Nr   )
rF   r@   r   r   rX   r   PartNamer:   openrY   )rZ   rH   readerstrings_pathr_   s        r;   read_stringszExcelReader.read_strings   sz    \\~.">>#F>;;qr?L""<1 2S&,Sk#2 2 2 2s   $A<<Bc                    t        | j                        }t        | j                  |j                  dd  | j
                        | _        | j                  j                          | j                  j                  }g |_	        | j                  |_        | j                  |_        |j                  t        t         fv |_        | j$                  rdt'        t)               dt*              |_        | j.                  D ]7  }|j,                  j1                  || j                  j3                  |             9 | j                  r| j                  |_        || _        y )Nr   )rW   a)rM   rF   r   r:   rc   rW   parserparsewb_sheetsrV   
_data_onlyrT   
_read_onlyrB   r   r   templaterU   r   r   r   vba_archiverS   writestrr+   _archive)rZ   wb_partrl   names       r;   read_workbookzExcelReader.read_workbook   s    %dll3$T\\73C3CAB3GTXTcTcd[[^^
))dD\9 ==$WY\BBN(( G''dll.?.?.EFG >>,,BKr=   c                     t         | j                  v rMt        | j                  j	                  t                     }t        j                  |      | j                  _        y y rQ   )	r
   rS   r(   r:   r+   r   r^   rl   
propertiesrZ   r_   s     r;   read_propertieszExcelReader.read_properties   sE    t'''T\\..x89C!3!=!=c!BDGG (r=   c                     t         | j                  v rMt        | j                  j	                  t                     }t        j                  |      | j                  _        y y rQ   )	r   rS   r(   r:   r+   r   r^   rl   custom_doc_propsry   s     r;   read_customzExcelReader.read_custom   sE    )))T\\..z:;C'9'C'CC'HDGG$ *r=   c                     t         | j                  v r/| j                  j                  t               | j                  _        y y rQ   )r   rS   r:   r+   rl   loaded_theme)rZ   s    r;   
read_themezExcelReader.read_theme   s0    (((#'<<#4#4Y#?DGG  )r=   c                 |   |j                   }t        |      }g }|| j                  v rt        | j                  |      }| j                  j                  |d      5 }|j                         }d d d        t              }t        j                  |      }	| j                  |	_        |j                  |	_        | j                  j                  |	       |j                  t         j"                        }
|
D ]=  }t%        | j                  |j                         \  }}|D ]  }|	j'                  |        ? y # 1 sw Y   xY w)Nr.   )targetr"   rS   r!   r:   rd   r+   r(   r%   r^   rl   _parentru   title
_add_sheetr@   r'   	_rel_typer)   	add_chart)rZ   sheetrel
sheet_path	rels_pathrelsr_   xmlnodecsdrawingschartsimagescs                 r;   read_chartsheetzExcelReader.read_chartsheet   s   ZZ
!*-	(((!$,,	:D\\z3/ 	3((*C	#!!$'WW
::299/99: 	 C(szzBNFF  Q 	 	 	s   D22D;c           
      $	   d}| j                   j                         D ]  \  }}|j                  | j                  vr d|j                  v r| j                  ||       At        |j                        }t               }|| j                  v rt        | j                  |      }| j                  rmt        | j                  |j                  |j                  | j                        }|j                  |_        | j                  j"                  j%                  |       | j                  j'                  |j                        }| j                  j)                  |j                        }||_        t-        ||| j                  | j.                  | j0                        }|j3                          |j5                          |j7                  t8              D ]d  }	| j                  j;                  |	j                        }
t=        j>                  tA        |
            }|jB                  D ]  \  }}	 |||   _"         f | j                  jV                  r7|jX                  r+|j[                  |jX                        j                  |_,        nd |_,        |j\                  D ]N  }| j                  j;                  |      }
tA        |
      }t_        j>                  |      }|ja                  |       P |j7                  tb        jd                        }|D ]k  }tg        | j                  |j                        \  }}|D ]  }|ji                  ||jj                           |D ]  }|jm                  ||jj                           m |j7                  tn        jp                        }| j                   jr                  }|D ]n  }	|	jt                  }| j                  j;                  |      }
tA        |
      }to        j>                  |      }||jv                     |_<        |j{                  |       p |j                  |_         y # tF        $ rU ||   }tI        |tJ              r<tM        jN                  |jQ                  |jR                  |jT                               Y lY ow xY w)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)>rj   find_sheetsr   rS   Typer   r"   r    r!   r:   rT   r#   rl   ru   rY   statesheet_staterm   appendrd   create_sheet_relsr$   rV   rX   bind_allcloser@   r   r+   r   r^   r(   commentscommentAttributeError
isinstancer   warningswarnformatr   
coordinaterq   legacy_drawinggettablesr&   	add_tabler'   r   r)   r   anchor	add_imager   rel_typepivot_cachesTargetcacheIdcache	add_pivot)rZ   comment_warningr   r   r   r   wsfh	ws_parserr.   r_   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 E	)JE3zz!1!11sxx'$$UC0%cjj1I#%DD,,,%dllI>~~&tww

CJJH[H[\!&&&r*\\&&szz2WW))%**5+BD4G4GY]YgYgh	""$
 YY{+ 
%ll''1 , 6 6z# G$1$:$: %LC%*13%
% ww""r'8'8$(HHR->->$?$F$F!$(!%% $ll''* o,U#	$ yy!3!=!=>H 0!,T\\3::!F .ALLAHH-.  0BLLRYY/0	0 		/":":;I;;33L $XX
ll''
3!#'11$7*5==9U#$ #[[BNKE	)B * %sG%a4$MM/*@*@1<<*XY$ 5%s   &
P11AR	R	c                 <   d}	 | j                          d}| j                          d}| j                          d}| j                          d}| j	                          d}| j                          d}t        | j                  | j                         d}| j                          d	}| j                  j                          | j                  s| j                  j                          y y # 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.)ra   rg   rv   rz   r}   r   r   r:   rl   r   rj   assign_namesrT   r   
ValueErrorr6   )rZ   actiones      r;   r+   zExcelReader.read  s	    	 #F$F &F  "-F!FOO&FT\\4773&F  "#FKK$$&>>""$ " 	5fXVDLLDYDYCZ [= = 		s   C C& &	D/'DDN)__name__
__module____qualname____doc__r   r\   ra   rg   rv   rz   r}   r   r   r   r+    r=   r;   rO   rO   s   sL     &+X TU	!02.CI@
 ,G)Tr=   rO   Tc                 Z    t        | |||||      }|j                          |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.

    )rO   r+   rl   )r6   rT   rU   rV   rW   rX   re   s          r;   load_workbookr   <  s.    < 9h"J	;F
KKM99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<   rM   rO   r   r   r=   r;   <module>r      s    $ *    0 
 ;    % 8 6 $ 7 6 8 :  < 6 * * C - ! 9 B: F FR ',h!de!W	  Hs   C
 
CC