http://scienceoss.com/read-excel-files-from-python/comment-page-1/#comment-1051使用xlrd讀取包含中國和/或印地文字符
從上面的鏈接的Excel xls文件,我用這個工具來讀取XLS文件。如果XLS文件包含不同的語言字符(如中文或印地文),則不會正確輸出它們。有沒有解決方法?
谷歌搜索後,我發現這一點:
import xlrd
def upload_xls(dir,file,request):
try:
global msg
global row_num
row_num = []
header_arr = []
global file_path
file_path = dir
#reader = csv.reader(open(file), delimiter='#', quotechar='"')
book = xlrd.open_workbook('dodgy.xls',encoding='cp1252') ##To specify UTF8-encoding
wb.sheet_names()
sh = wb.sheet_by_index(0)
valid_xl_format = 0
invalid_xl_format = 0
except:
print "Error
但有一個錯誤在該行book = open_workbook('dodgy.xls',encoding='cp1252')
:
TypeError: open_workbook() got an unexpected keyword argument 'encoding'
你能發佈您的代碼的其他人呢?這條線給出的確切的錯誤?這聽起來像你正在嘗試使用你還沒有定義或導入的函數。 – 2010-08-18 12:00:01
請參閱編輯.. – Hulk 2010-08-18 12:05:55
您沒有閱讀CSV,您正在閱讀XLS。 – katrielalex 2010-08-18 12:35:15