python3 读写excel

一直认为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'),

再运行程序,搞定

转载于:https://www.cnblogs.com/luhouxiang/p/4920132.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值