'openpyxl problem Keyerror Content_Types.xml
I have a problem reading the code with openpyxl, until yesterday it works, and now it doesn't work anymore, I tried also with a backup copy but I have the same problem, I deleted the excel files... I also tried on another computer and I have the same error. this is the code:
# Writing on a EXCEL FILE
filename = (f"{myPath}/Monatsplan {userfinder} {month} {year}.xlsx")
dienstorinfo = string1
emptycell = ' '
x = len(dienstorinfo)
if x == 0:
dienstorinfo = tagesinfo2
try:
wb = load_workbook(filename)
ws = wb.worksheets[0] # select first worksheet
except FileNotFoundError:
headers_row = ['Datum','Dienst','Funktion','Von','Bis','Schichtdauer','Bezahlte Zeit','Überzeit','Sonnats Zulage','Nachtdienst']
wb = Workbook()
ws = wb.active
wb.save(filename)
ws.append([soup_datum,dienstorinfo,soup_funktion,(soup_dienstbegin),(soup_dienstende),(soup_schichtdauer),(soup_bezahltezeit),emptycell,emptycell])
for cols in ws.iter_cols( ):
if cols[-1].value:
cols[-1].border = Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),bottom=Side(style='thin'))
ws.column_dimensions['A'].width = 11
ws.row_dimensions['1'].height = 25
ws.column_dimensions['B'].width = 60
ws.column_dimensions['C'].width = 2
ws.column_dimensions['D'].width = 3
ws.column_dimensions['E'].width = 3
ws.column_dimensions['F'].width = 3
ws.column_dimensions['H'].width = 3
ws.column_dimensions['I'].width = 2
ws.column_dimensions['L'].width = 2
wb.save(filename)
wb.close()
a this is the response:
Traceback (most recent call last):
File "c:\Users\Diriye\OneDrive\Python\tuxapp\Monatseint_Tool_v1.1.py", line 408, in <module>
scraping()
File "c:\Users\Diriye\OneDrive\Python\tuxapp\Monatseint_Tool_v1.1.py", line 364, in scraping
excel()
Traceback (most recent call last):
File "c:\Users\Diriye\OneDrive\Python\tuxapp\Monatseint_Tool_v1.1.py", line 408, in <module>
scraping()
File "c:\Users\Diriye\OneDrive\Python\tuxapp\Monatseint_Tool_v1.1.py", line 364, in scraping
excel()
File "c:\Users\Diriye\OneDrive\Python\tuxapp\Monatseint_Tool_v1.1.py", line 340, in excel
wb = load_workbook(filename)
File "C:\Users\Diriye\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openpyxl\reader\excel.py", line 317, in load_workbook
reader.read()
File "C:\Users\Diriye\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openpyxl\reader\excel.py", line 276, in read
self.read_manifest()
File "C:\Users\Diriye\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\openpyxl\reader\excel.py", line 134, in read_manifest
src = self.archive.read(ARC_CONTENT_TYPES)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1463, in read
with self.open(name, "r", pwd) as fp:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1502, in open
zinfo = self.getinfo(name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1429, in getinfo
raise KeyError(
KeyError: "There is no item named '[Content_Types].xml' in the archive"
Solution 1:[1]
The issue for me that i created and .ods file type, and rename it to .xlsx file. if this is the case for you or others To solve the issue you need to convert the .ods to .xlsx, I used online converter and it worker for me. https://www.zamzar.com/convert/ods-to-xls/
make sure to specify .xlsx as file type
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Elie Eid |
