LoginSignup
2
0

More than 3 years have passed since last update.

xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record;

Last updated at Posted at 2020-10-07
  • 環境
    • Windows10 Pro バージョン1909
    • Python 3.8.5
    • Pandas 1.0.5

事象 : PandasでExcelファイルを読み込もうとしたら怒られた

PythonでExcelファイルを読み込むコードを作ってPyInstallerでexeファイルにしてディレクトリを変えてコマンドプロンプトで実行したら怒られた。

> my-code.exe
処理を開始しました。
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():
    # Excelファイルを読み込む
    book = pd.read_excel(excel_file, sheet_name=None, header=None)

原因 : ごみファイルがあるから

Excelファイルを開いたときにできる~$で始まるファイルが残っていた・・・
Excelファイルを閉じても残るときがある・・・エクスプローラーで見えなかったがdirコマンドで見えた・・・

> dir data\
# ...省略...
2020/10/07  10:30               165 ~$処理対象のExcel.xlsm

対応 : ごみファイルを消す

# ごみファイルを削除する
> cd data\
> del "~$処理対象のExcel.xlsm"

# ごみがなくなったら動いた
> cd ../
> my-code.exe
処理を開始しました。
処理が終了しました。
2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0