2016-08-24 86 views
0

,當我試圖通過下面的代碼讀取Excel文件:XLRDError閱讀的XLS文件

import os 
import xlrd 

files = os.listdir(".")[1:101] 


for file in files: 
    workbook = xlrd.open_workbook(file) 

,但我得到一個錯誤信息是這樣的。

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\r\n\r\n\r\n\r\n'

所以我試着一個一個打開文件。

而且我發現命名爲這樣的文件是可讀的,命名爲喜歡這種格式 「14.08.01-08.07.xlsx.xlsx」 但文件無法讀取。 「14.08.22-08.28.xlsx.xls

於是我打開的文件,發現帶擴展名「xlsx.xls」文件有問題,編碼。

這些文件包含韓文字符,所以我試圖通過將編碼更改爲utf-8來打開它們,這是徒勞的。

總之,我認爲我不能讀取xlsx.xls文件,因爲編碼問題。

有沒有辦法解決這類問題?

+0

也許[這](http://stackoverflow.com/questions/3511743/using-xlrd-to-read-excel-xls-file-containing-chinese-and-or-hindi-字符)有幫助嗎? – lrnzcig

+0

他們是'xls'還是'xlsx'格式 - 奇怪的文件擴展名命名在那裏... –

回答

1

嘗試xlrd.open_workbook(file, encoding_override="utf-8")