'opening xlsx (from open office) in python

Once again I try to do a program from the book automate the boring stuff with python. page 266 starts the work with excel sheets. I imported the example sheet, which I downloaded. Worked. Then I createt my own sheet with open office, but I get an error. Whats the problem here? File type and path is the same, why I get an error?

edit: I downloaded the newest openoffice version in english (usually I would use german). I right click in the python folder and created new file, openoffice sheet. It creates a *.odt file first. I open it. I "save as" the file and type in the name 123.xlsx. It does not show me the file type xlsx available, thats why I type in the name directly. Maybe thats the problem. But the file gets saved without error and works, so I also dont see a problem in there.

#code
import openpyxl    
wb = openpyxl.load_workbook('123.xlsx')

#error
Traceback (most recent call last):
  File "C:\...\Python\Python37-32\B&J_Datensatz.py", line 7, in <module>
    wb = openpyxl.load_workbook('123.xlsx')
  File "C:\...\Python\Python37-32\lib\site-packages\openpyxl\reader\excel.py", line 176, in load_workbook
    src = archive.read(ARC_CONTENT_TYPES)
  File "C:\...\Python\Python37-32\lib\zipfile.py", line 1428, in read
    with self.open(name, "r", pwd) as fp:
  File "C:\...\Python\Python37-32\lib\zipfile.py", line 1467, in open
    zinfo = self.getinfo(name)
  File "C:\...\Python\Python37-32\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"


Solution 1:[1]

I solved the problem, kind of. I downloaded libreoffice. With that program I can save directly to *.xlsx files. As I said, openoffice could not. Thanks everybody for help!

Solution 2:[2]

when you using libreoffice, it automatically saves in ods format. you need to open the file and save it back (here the application automatically asks to save in excel) and make sure.xlsx to be saved

Solution 3:[3]

I was getting this error entirely unrelated to using open office. For anyone else getting this error, here's how I solved it:

  • Copy the contents into google sheets
  • Make a new excel file
  • Copy the contents of the google sheets into the new excel file

The google sheets is needed to reformat the excel data, as it is corrupted. There's probably a more technical way to fix it, but this is how you can do it quickly.

Solution 4:[4]

your input file is corrupted,

please make a new copy of input file & try.

it worked for me

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 mnl1337
Solution 2 Anil kumar
Solution 3 Malcolm Hollett
Solution 4 KRISHNA CHAITANYA