[Python] Error while loading excel file with Openpyxl

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying yo load an excel file using Openpyxl in Python.

    from openpyxl import load_workbook
    wb2 = load_workbook('Book1.xlsx')
    print wb2.get_sheet_names()


    It just these three lines. and it throws the following error:

    Traceback (most recent call last):
    File "C:/Python27/excel1.py", line 5, in <module>
    wb2 = load_workbook('Book1.xlsx')
    File "C:\Python27\Lib\site-packages\openpyxl\reader\excel.py", line 141, in load_workbook
    archive = ZipFile(f, 'r', ZIP_DEFLATED)
    File "C:\Python27\Lib\zipfile.py", line 793, in __init__
    self._RealGetContents()
    File "C:\Python27\Lib\zipfile.py", line 835, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
    BadZipfile: File is not a zip file


    This is exactly like their Documentation. https://openpyxl.readthedocs.org/en/latest/tutorial.html Is their any better package to do this.

    Continue reading...

Compartilhe esta Página