Python Forum
I am getting a KeyError, after file save, My goal is to after changes save file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am getting a KeyError, after file save, My goal is to after changes save file
#1
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.
Reply


Messages In This Thread
I am getting a KeyError, after file save, My goal is to after changes save file - by ervijay587 - Dec-05-2018, 05:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python editor that will SFTP automatically on save sawtooth500 1 267 Apr-30-2024, 05:13 AM
Last Post: Gribouillis
  Copy xml content from webpage and save to locally without special characters Nik1811 14 1,059 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  Open/save file on Android frohr 0 353 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,211 Dec-14-2023, 08:03 AM
Last Post: shanoger
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 505 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Goal Seek tdutcher05 1 839 Nov-17-2023, 10:33 PM
Last Post: deanhystad
  save a session in idle akbarza 5 810 Nov-06-2023, 08:36 AM
Last Post: snippsat
  how to save to multiple locations during save cubangt 1 581 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Need to replace a string with a file (HTML file) tester_V 1 796 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  change directory of save of python files akbarza 3 948 Jul-23-2023, 08:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020