What to do when xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record;

--Environment --Windows10 Pro version 1909 - Python 3.8.5 - Pandas 1.0.5

Event: I got angry when I tried to read an Excel file with Pandas

I made a code to read an Excel file with Python, made it an exe file with PyInstaller, changed the directory and executed it at the command prompt, and I got angry.

> my-code.exe
The check process has started. Do not close the screen.
Traceback (most recent call last):
  File "my-code.py", line 256, in <module>
  File "my-code.py", line 218, in check_files
  File "pandas\io\excel\_base.py", line 304, in read_excel
  File "pandas\io\excel\_base.py", line 824, in __init__
  File "pandas\io\excel\_xlrd.py", line 21, in __init__
  File "pandas\io\excel\_base.py", line 353, in __init__
  File "pandas\io\excel\_xlrd.py", line 36, in load_workbook
  File "xlrd\__init__.py", line 148, in open_workbook
  File "xlrd\book.py", line 92, in open_workbook_xls
  File "xlrd\book.py", line 1278, in getbof
  File "xlrd\book.py", line 1272, in bof_error
xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\t\x92\x86\x88\xe4 \x90^'
[12704] Failed to execute script my-code

my-code.py


import pandas as pd

def check_files():
    #Read an Excel file
    book = pd.read_excel(excel_file, sheet_name=None, header=None)

Cause: There is a garbage file

There was a file that started with ~ $ that was created when I opened the Excel file ... Sometimes it remains even after closing the Excel file ... I couldn't see it in Explorer, but I could see it with the dir command ...

> dir data\
# ...abridgement...
2020/10/07  10:30               165 ~$Excel to be processed.xlsm

Action: Delete the garbage file

#Delete garbage files
> cd data\
> del "~$Excel to be processed.xlsm"

#It worked when there was no garbage
> cd ../
> my-code.exe
The check process has started. Do not close the screen.
The processing of the tool is finished.

Recommended Posts

What to do when xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record;
What to do when [Errno 2] No such file or directory appears in Python
What to do when gdal_merge creates a huge file
What to do when raise ValueError, "unsupported hash type"
What to do when PyCharm font is strange or garbled
What to do when Ubuntu crashes
What to do when PermissionError of tempfile.mkstemp occurs
What to do if ENOENT: no such file or directory appears during npm install
[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
curl: (60) What to do when Issuer certificate is invalid.
What to do when "cannot import name xxx" [Python]
How to convert Json file to CSV format or EXCEL format
What to do when you can't bind CaboCha to Python
[AWS] What to do when you want to pip with Lambda
What to do when Japanese is not displayed on matplotlib
What to do when a Remove Error occurs when updating conda
What to do when Unalignable boolean Series provided as indexer
TypeError: unsupported operand type (s) for-: What to do when'datetime.time'and'datetime.time'
What to do when an error occurs with import _ssl
What to do if package installation fails when deploying to heroku
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
ImportError: No module What to do when you are told
[Beginner] What to do when "[Errno 2] File b'test.csv' does not exist: b'test.csv" is displayed when reading pandas csv
A story about what to do when a bad interpreter: Not such file or directory appears in Anaconda3 and how to investigate the cause.