iE0dZddlmZmZddlmZddlZddlZddl m Z  ddl m Z n #e $rdZ YnwxYwdd lmZdd lmZmZmZmZmZmZmZmZmZmZmZdd lmZdd lmZd dl m!Z!m"Z"d dl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddlm?Z?dZ@dZAdZBGdd ZCde dd!dfd"ZDdS)#zRead an xlsx file into Python)ZipFile ZIP_DEFLATED)BytesION)TableDefinition)KEEP_VBAF)InvalidFileException) ARC_CORE ARC_CUSTOMARC_CONTENT_TYPES ARC_WORKBOOK ARC_THEME COMMENTS_NSSHARED_STRINGSXLTMXLTXXLSMXLSX) MergedCell) CommentSheet)read_string_tableread_rich_text)WorkbookParser)apply_stylesheet)DocumentProperties)CustomPropertyList)ManifestOverride)RelationshipListget_dependents get_rels_path)ReadOnlyWorksheet)WorksheetReader) Chartsheet)Table)SpreadsheetDrawing) fromstring) find_images)z.xlsxz.xlsmz.xltxz.xltmcLt|d}|stj|d}|t vrA|dkrd}n)|dkrd}n d|dd 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 openpyxlzopenpyxl does not support zT file format, please check you can open it with Excel first. Supported formats are: ,r) hasattrospathsplitextlowerSUPPORTED_FORMATSjoinr r)filename is_file_like file_formatmsgarchives CC:\PYTHON\_runtimes\venv\Lib\site-packages\openpyxl/reader/excel.py_validate_archiver<Bs8V,,L ,g&&x004::<< / / /f$$<''2(8C{{7:xx@Q7R7R7R T 's++ +h$$G Nc2ttttg}|D]}||}|r|cSd|jD}|t |z}|r*tdtz| Std)Nch|] }|j S) ContentType).0ps r; z&_find_workbook_part..ks777! 777r=/z$File contains no valid workbook part) rrrrfindDefaultsetrr popIOError)packageworkbook_typesctpartdefaults workbook_types r;_find_workbook_partrQcsD$-N||B  KKK 87w777Hs>222MAl*M,=,=,?,?@@@ 8 9 99r=cZeZdZdZdedddfdZdZdZdZdZ d Z d Z d Z d Z d ZdS) ExcelReaderzQ Read an Excel package and dispatch the contents to the relevant modules FTct||_|j|_||_||_||_||_||_g|_ dSN) r<r:namelist valid_files read_onlykeep_vba data_only keep_links rich_textshared_strings)selffnrXrYrZr[r\s r;__init__zExcelReader.__init__ysX(,, <0022"  "$" r=c|jt}t|}t j||_dSrU)r:r+r r(r from_treerK)r^srcroots r; read_manifestzExcelReader.read_manifests9l 122#)$// r=c|jt}t}|jrt }|T|jdd}|j|5}|||_ ddddS#1swxYwYdSdS)Nr) rKrFrrr\rPartNamer:openr])r^rMreader strings_pathrcs r; read_stringszExcelReader.read_stringss \  ~ . ." > $#F >;qrr?L""<11 2S&,fSkk# 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 >s A>>BBcPt|j}t|j|jdd|j|_|j|jj}g|_ |j |_ |j |_ |jtt fv|_|jrdt't)dt*|_|jD]5}|j||j|6|j r |j|_||_dS)Nr)r[a)rQrKrr:rgr[parserparsewb_sheetsrZ _data_onlyrX _read_onlyrArrtemplaterYrrr vba_archiverWwritestrr+_archive)r^wb_partrpnames r; read_workbookzExcelReader.read_workbooks%dl33$T\73CABB3GTXTcddd   [^   )dD\9  = G$WYY\BBBN( G G''dl.?.?.E.EFFFF > ',BKr=ct|jvrLt|jt}t j||j_dSdSrU) r rWr(r:r+rrbrp propertiesr^rcs r;read_propertieszExcelReader.read_propertiessP t' ' 'T\..x8899C!3!=c!B!BDG    ( 'r=ct|jvrLt|jt}t j||j_dSdSrU) r rWr(r:r+rrbrpcustom_doc_propsr}s r; read_customzExcelReader.read_customsP ) ) )T\..z::;;C'9'CC'H'HDG $ $ $ * )r=cxt|jvr+|jt|j_dSdSrU)rrWr:r+rp loaded_theme)r^s r; read_themezExcelReader.read_themes8 ( ( (#'<#4#4Y#?#?DG  ) (r=c`|j}t|}g}||jvrt|j|}|j|d5}|}dddn #1swxYwYt|}tj |} |j | _ |j | _ |j | |t j} | D]9}t%|j|j\} } | D]} | | :dS)Nr.)targetr"rWr!r:rhr+r(r%rbrp_parentrytitle _add_sheetrFr' _rel_typer) add_chart)r^sheetrel sheet_path rels_pathrelsrcxmlnodecsdrawingschartsimagescs r;read_chartsheetzExcelReader.read_chartsheets^Z !*--  ( ( (!$, ::D \  z3 / / 3((**C               #  !$ ' 'W : 299/9::  C(szBBNFF   Q   sA33A7:A7c 2d}|jD]\}}|j|jvrd|jvr|||5t |j}t}||jvrt|j |}|j rRt|j |j |j|j}|j|_|j j||j |j}|j |j }||_t-|||j|j|j}|||t8D]} |j | j} t=jtA| } | j!D]t\} } | || _"#tF$rT|| }tI|tJr4tMj'|(|j)|j*YoYqwxYw|j j+r,|j,r%|-|j,j|_,nd|_,|j.D]T}|j |} tA| }t_j|}|0|U|tbj2}|D]_}tg|j |j\}}|D]}|4||j5|D]}|6||j5`|tnj8}|jj9}|D]m} | j:}|j |} tA| }toj|}||j;|_<|=|n|j|_dS)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_sheetsrrWTyperr"r r!r:rXr#rpryr]state sheet_staterqappendrh create_sheet_relsr$rZr\bind_allcloserFrr+rrbr(commentscommentAttributeError isinstancerwarningswarnformatr coordinaterulegacy_drawinggettablesr& add_tabler'rr)ranchor add_imagerrel_type pivot_cachesTargetcacheIdcache add_pivot)r^comment_warningrrrrwsfh ws_parserr.rc comment_sheetrefrrtrtablerrrim pivot_relr pivot_pathtreepivots r;read_worksheetszExcelReader.read_worksheetss_+1133E )E )JE3z!111sx''$$UC000%cj11I#%%DD,,,%dlI>>~ &tw CJH[\\!&&&r***\&&sz22W))%*55+BD4GY]Yghh ""$$$ YY{++ % %l''11 , 6z# G G $1$:%%LC%*13)%%%sG%a44%$M/*@*@1<*X*XYYY$H%%%%w" )r'8 )$(HHR->$?$?$F!!$(!% $ $l''** oo,, U####yy!3!=>>H 0 0!,T\3:!F!F..ALLAH---- 00BLLRY////0 /":;;I;3L $ $X l'' 33!#'1$77*5=9  U####"[BNNKE )E )s" G00AI I cTd} |d}|d}|d}|d}|d}|d}t |j|jd}| d }|j |j s|j dSdS#t$r&}td |d |jjd |d}~wwxYw) Nz read manifestz read stringsz read workbookzread propertieszread custom propertiesz read themezread stylesheetzread 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.)rerkrzr~rrrr:rprrn assign_namesrXr ValueErrorr6)r^actiones r;r+zExcelReader.readsc      #F      $F    &F  " " "-F      !F OO   &F T\47 3 3 3&F  " " "#F K $ $ & & &> % ""$$$$$ % %   =f==DLDY===   sC/C77 D'!D""D'N)__name__ __module__ __qualname____doc__rr`rerkrzr~rrrrr+r@r=r;rSrSss&+X TU ! ! ! !000 222.CCC III @@@    ,G)G)G)Tr=rSTc`t||||||}||jS)aEOpen 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. )rSr+rp)r6rXrYrZr[r\ris r; load_workbookr<s5<9h"J ;;F KKMMM 9r=)Erzipfilerrioros.pathr0ropenpyxl.pivot.tablertestsr ImportErroropenpyxl.utils.exceptionsr openpyxl.xml.constantsr r r r rrrrrrr openpyxl.cellropenpyxl.comments.comment_sheetrstringsrrworkbookropenpyxl.styles.stylesheetropenpyxl.packaging.coreropenpyxl.packaging.customropenpyxl.packaging.manifestrropenpyxl.packaging.relationshipr r!r"openpyxl.worksheet._read_onlyr#openpyxl.worksheet._readerr$openpyxl.chartsheetr%openpyxl.worksheet.tabler&$openpyxl.drawing.spreadsheet_drawingr'openpyxl.xml.functionsr(rr)r4r<rQrSrr@r=r;rs$#*)))))))000000       HHH;:::::                          %$$$$$88888866666666$$$$$$777777666666888888:::::::: <;;;;;666666************CCCCCC------!!!!!!9B : : : FFFFFFFFR',h!de!!!!!!s '11