一直認為python3可以很快的實現很多簡單的功能,今天要讀excel表格數據,想來很簡單,網上一搜,用xlrd即可,然后很多人給出了不同的版本,號稱xlrd3,實際上官網一看,xlrd0.9.4兼容2和3,因此直接下載即可,網址:https://pypi.python.org/pypi/xlrd
下載后解壓,然后通過命令行進入下載的目錄,然后C:\python34\python.exe setup.py install即可(我的python安裝在C盤,是3.4版)
然后輸入以下代碼:
#!/usr/bin/env python3
#coding: utf-8
import xlrd
wb = xlrd.open_workbook("D:\\send\\mydata.xls")
sh=wb.sheet_by_index(0)#第一個表
cellName = sh.cell(3,2).value
print(cellName)
發現這個錯誤出現了:Python XLRD Error : formula/tFunc unknown FuncID:186
找了好久,終於國外有個家伙也碰到了,網址如下:http://stackoverflow.com/questions/29971186/python-xlrd-error-formula-tfunc-unknown-funcid186
解決方案的原文回答如下:
For now I just wanted to make sure the xlrd read fine. I hacked my xlrd package so that it loads.
I don't gaurentee the correctness of the output.
Just add the following line in formula.py of your pythonlibs/xlrd package.
Around line 240 where each number is map to a function create a hacked function here. I've inserted 'HACKED' in there. I don't understand exactly what's going on.
-- added the line that starts with 186:
184: ('FACT', 1, 1, 0x02, 1, 'V', 'V'),
186: ('HACKED', 1, 1, 0x02, 1, 'V', 'V'),
189: ('DPRODUCT', 3, 3, 0x02, 3, 'V', 'RRR'),
Here is the discussion by xlrd group. Essentially, this is a complicated problem that can't be resolved. :)
很清楚了,找到formula.py文件186行左右,在文字184和文字189中間加插入一行186: ('HACKED', 1, 1, 0x02, 1, 'V', 'V'),
再運行程序,搞定
