openpyxl error "There is no item named '[Content_Types].xml' in the archive"

13.7k views Asked by At

I have a problem with openpyxl, when I want to start the script I get this error, until yesterday it worked and now no more, I tried to uninstall the module, but the problem persists, the excel files I deleted it and nowhere is it open. any ideas?

import openpyxl
from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.styles import Border, Side, PatternFill, Font, GradientFill, Alignment
from openpyxl.styles import colors
from openpyxl.cell import Cell
from termcolor import colored, cprint
from openpyxl.styles import numbers

from os import mkdir
myPath = '.\Erstellte Datein' # initialize the Chrome driver

def excel():
                
                # Writing on a EXCEL FILE
                filename = (f"{myPath}/Monatsplan openpytesst.xlsx")
                dienstorinfo = 'texttest'
                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(['1','2','2','4','5'])
                wb.close()

                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()
excel()

enter image description here

1

There are 1 answers

0
King Chudi On

It's either your .xlsx file is corrupt or you are referencing the wrong file.

Get a new .xlsx file or look for the file that is not corrupt and start working, this worked for me.