Excel files under the hood are a zip archive of xml files. One can access individual xmls without opening the Excel application:
import zipfile
with zipfile.ZipFile('some_workbook.xlsx', 'r') as zf:
zf.read('some.xml')
But for workbooks encrypted with password this doesn't work.
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-8-64b8af6320bd>", line 1, in <module>
with zipfile.ZipFile('Book1.xlsm', 'r') as zf:
File "C:\ProgramData\Anaconda3\Lib\zipfile.py", line 1108, in __init__
self._RealGetContents()
File "C:\ProgramData\Anaconda3\Lib\zipfile.py", line 1175, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
Does anyone know how to access the encrypted workbook as a zip archive without opening Excel first and removing the password? I do know the password, just don't want to open excel to remove it.
I'm looking for a programmatic approach with Python, not interested in 3rd party software.