Dec-05-2018, 05:52 AM
(This post was last modified: Dec-05-2018, 06:21 AM by Gribouillis.)
This is my Code:
import openpyxl from openpyxl import load_workbook #load existing excel file from the storage wb = load_workbook("test1.xlsx") print(wb._active_sheet_index) #Print sheet name you want to activate activate_yoursheet = input("Enter your sheet name to activate:") #List all sheetnames for sheet in wb: #print(sheet.title) if(sheet.title == activate_yoursheet): break wb.active = activate_yoursheet print("Your activated sheet is now:", wb._active_sheet_index) wb.save("test1.xlsx")The Traceback I get is this:
Error:Traceback (most recent call last):
File "xcel.py", line 6, in <module>
wb = load_workbook("test1.xlsx")
File "C:\Python37\lib\site-packages\openpyxl-2.5.0-py3.7.egg\openpyxl\reader\e
xcel.py", line 177, in load_workbook
src = archive.read(ARC_CONTENT_TYPES)
File "C:\Python37\lib\zipfile.py", line 1428, in read
with self.open(name, "r", pwd) as fp:
File "C:\Python37\lib\zipfile.py", line 1467, in open
zinfo = self.getinfo(name)
File "C:\Python37\lib\zipfile.py", line 1395, in getinfo
'There is no item named %r in the archive' % name)
KeyError: "There is no item named '[Content_Types].xml' in the archive"
I didn't try anything new, what I thought is it may be a problem with a type of file I am using, i.e. binary or may UTF type of file will work but I don't know how to proceed further.