U o^z*@sdZddlmZmZmZddlmZddlmZddl Z ddl Z ddl m Z zddlmZWnek rtd ZYnXdd lmZdd lmZmZmZmZmZmZmZmZmZmZmZmZdd l m!Z!dd l"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-m.Z.ddl/m0Z0m1Z1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;mZ>ddl?m@Z@dZAddZBdd ZCGd!d"d"ZDd ed d#fd$d%ZEdS)&zRead an xlsx file into Python)ZipFile ZIP_DEFLATED BadZipfile)exc_info)BytesION)TableDefinition)KEEP_VBAF)InvalidFileException) ARC_SHARED_STRINGSARC_COREARC_CONTENT_TYPES ARC_WORKBOOK ARC_THEME COMMENTS_NSSHARED_STRINGS EXTERNAL_LINKXLTMXLTXXLSMXLSX) MergedCell) CommentSheet)read_string_table)WorkbookParser)apply_stylesheet)DocumentProperties)ManifestOverride)RelationshipListget_dependents get_rels_path)ReadOnlyWorksheet)WorksheetReader) Chartsheet)Table)SpreadsheetDrawing) fromstring) find_images)z.xlsxz.xlsmz.xltxz.xltmcCsnt|d}|s`tj|d}|tkr`|dkr8d}n |dkrFd}nd|dtf}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 openpyxlzropenpyxl does not support %s file format, please check you can open it with Excel first. Supported formats are: %s,r) hasattrospathsplitextlowerSUPPORTED_FORMATSjoinr r)filenameZ is_file_likeZ file_formatmsgarchiver8o/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/openpyxl/openpyxl/reader/excel.py_validate_archiveCs  r:cCsjttttg}|D]}||}|r|Sqdd|jD}|t|@}|r^tdt| St ddS)NcSsh|] }|jqSr8) ContentType).0pr8r8r9 lsz&_find_workbook_part../z$File contains no valid workbook part) rrrrfindZDefaultsetrrpopIOError)packageZworkbook_typesctpartdefaultsZ workbook_typer8r8r9_find_workbook_partds    rHc@sbeZdZdZdeddfddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS) ExcelReaderzQ Read an Excel package and dispatch the contents to the relevant modules FTcCs8t||_|j|_||_||_||_||_g|_dSN) r:r7namelist valid_files read_onlykeep_vba data_only keep_linksshared_strings)selffnrMrNrOrPr8r8r9__init__zs  zExcelReader.__init__cCs$|jt}t|}t||_dSrJ)r7r*r r(r from_treerD)rRsrcrootr8r8r9 read_manifests zExcelReader.read_manifestc CsH|jt}|dk rD|jdd}|j|}t||_W5QRXdS)Nr)rDr@rPartNamer7openrrQ)rRrEZ strings_pathrVr8r8r9 read_stringss  zExcelReader.read_stringscCst|j}t|j|jdd|jd|_|j|jj}g|_ |j |_ |j |_ |jttfk|_|jrttdt|_|jD]}|j||j|q||j r|j|_||_dS)Nr)rPa)rHrDrr7rYrPparserparsewb_sheetsrOZ _data_onlyrMZ _read_onlyr;rrtemplaterNrrr vba_archiverLwritestrr*Z_archive)rRZwb_partr_namer8r8r9 read_workbooks   zExcelReader.read_workbookcCs,t|jkr(t|jt}t||j_dSrJ) r rLr(r7r*rrUr_Z properties)rRrVr8r8r9read_propertiess zExcelReader.read_propertiescCst|jkr|jt|j_dSrJ)rrLr7r*r_Z loaded_themerRr8r8r9 read_themes zExcelReader.read_themec Cs|j}t|}g}||jkr(t|j|}|j|d}|}W5QRXt|}t |} |j | _ |j | _ |j | |tj} | D]*}t|j|j\} } | D]} | | qqdS)Nr-)targetr"rLr!r7rZr*r(r%rUr__parentrdtitleZ _add_sheetr@r' _rel_typer) add_chart)rRsheetrelZ sheet_path rels_pathrelsrVxmlnodecsdrawingschartsimagescr8r8r9read_chartsheets"     zExcelReader.read_chartsheetc Csvd}|jD]`\}}|j|jkr&qd|jkr>|||qt|j}t}||jkrdt|j |}|j rt |j |j |j|j}|j j|qn<|j |j}|j |j }||_t|||j|j}||tD]} |j | j} tt| } | jD]\\} } z| || _Wqtk rX|| }t |t!rTt"#|$|j%|j&YqYqXqq|j j'r~|j(r~||j(j|_(|j)D].}|j |} t| }t*|}|+|q|t,j-}|D]L}t.|j |j\}}|D]}|/||j0q|D]}|1||j0qq|t2j3}|D]D} | j4}|j |} t| }t2|}|jj5|j6|_7|8|q"|j9|_:qdS)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.Z chartsheet);r]Z find_sheetsrirLZTyperyr"r r!r7rMr#r_rdrQr`appendrZZ create_sheetZ_relsr$rOZbind_allr@rr*rrUr(commentscommentAttributeError isinstancerwarningswarnformatrkZ coordinaterbZlegacy_drawingtablesr&Z add_tabler'rlr)rmanchorZ add_imagerZrel_typeZTargetZ pivot_cachesZcacheIdcacheZ add_pivotstateZ sheet_state)rRZcomment_warningrnrorprqwsfhZ ws_parserr-rVZ comment_sheetrefr|rxtrrtablerurvrwZimZ pivot_relZ pivot_pathtreeZpivotr8r8r9read_worksheetssl              zExcelReader.read_worksheetscCs\|||||t|j|j||j |j sX|j dSrJ) rXr[rerfrhrr7r_rr]Z assign_namesrMclosergr8r8r9r*s zExcelReader.readN)__name__ __module__ __qualname____doc__r rTrXr[rerfrhryrr*r8r8r8r9rIts ErITcCst|||||}||jS)aOpen 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. )rIr*r_)r5rMrNrOrPreaderr8r8r9 load_workbooks r)Frzipfilerrrsysrioros.pathr/rZopenpyxl.pivot.tablertestsr ImportErrorZopenpyxl.utils.exceptionsr Zopenpyxl.xml.constantsr r r rrrrrrrrrZ openpyxl.cellrZopenpyxl.comments.comment_sheetrstringsrZworkbookrZopenpyxl.styles.stylesheetrZopenpyxl.packaging.corerZopenpyxl.packaging.manifestrrZopenpyxl.packaging.relationshipr r!r"Zopenpyxl.worksheet._read_onlyr#Zopenpyxl.worksheet._readerr$Zopenpyxl.chartsheetr%Zopenpyxl.worksheet.tabler&Z$openpyxl.drawing.spreadsheet_drawingr'Zopenpyxl.xml.functionsr(rur)r3r:rHrIrr8r8r8r9sH     8             !*