コードとエラー
コード
import pandas as pd df= pd.read_excel("xxxx.xlsx")
エラーメッセージ
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1599, in <module> globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1026, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/testing/Dropbox/Test-XLwings/test.py", line 3, in <module> df = pd.read_excel('../TestXLWings.xlsm', sheetname="TestSheet") File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\excel.py", line 203, in read_excel io = ExcelFile(io, engine=engine) File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\excel.py", line 260, in __init__ self.book = xlrd.open_workbook(io) File "C:\ProgramData\Anaconda3\lib\site-packages\xlrd\__init__.py", line 441, in open_workbook ragged_rows=ragged_rows, File "C:\ProgramData\Anaconda3\lib\site-packages\xlrd\book.py", line 87, in open_workbook_xls ragged_rows=ragged_rows, File "C:\ProgramData\Anaconda3\lib\site-packages\xlrd\book.py", line 595, in biff2_8_load raise XLRDError("Can't find workbook in OLE2 compound document") xlrd.biffh.XLRDError: Can't find workbook in OLE2 compound document
原因
エラーの原因はエクセルファイルにロックが掛かっていたことでした
ロックを解除してエクセルを閉じて、再度実行すると正常に動作しました
コメント