AttributeError:'模块'对象没有属性'open_openwork' [英] AttributeError: 'module' object has no attribute 'open_openwork'
问题描述
我想导入一个EXCEL文件,但是代码有些错误.帮助!
import xlrdfname ="D:/pdf-ex/exc.xls"bk = xlrd.open_openwork("fname","rb")shxrange =范围(bk.nsheets)sh = bk.sheet_by_name("Sheet1")nrows = sh.nrowsncols = sh.ncols打印"nrows%d,ncols%d"%(nrows,ncols)cell_value = sh.cell_value(1,1)打印单元格值row_list = []对于我在范围(1,行)中的我:row_data = sh.row_values(i)row_list.append(row_data)
之所以这样,是因为 xlrd
模块中没有 open_openwork()
函数./p>
您可能正在寻找的功能是 open_workbook()
:
open_workbook(...)
-打开电子表格文件以进行数据提取.
另外,文档中的模式也没什么-通过提供第二个参数来设置日志文件(打开的文件对象将读取消息).
所以代替:
bk = xlrd.open_openwork("fname","rb")
这样做:
bk = xlrd.open_workbook("fname")
I want to import an EXCEL file ,but there is some wrong with the codes.Help!
import xlrd
fname = "D:/pdf-ex/exc.xls"
bk = xlrd.open_openwork("fname","rb")
shxrange = range(bk.nsheets)
sh = bk.sheet_by_name("Sheet1")
nrows = sh.nrows
ncols = sh.ncols
print "nrows %d, ncols %d" % (nrows,ncols)
cell_value = sh.cell_value(1,1)
print cell_value
row_list = []
for i in range(1,nrows):
row_data = sh.row_values(i)
row_list.append(row_data)
The reason for that is because xlrd
module does not have open_openwork()
function in it.
The function you may be looking for is open_workbook()
:
open_workbook(...)
- Open a spreadsheet file for data extraction.
Plus there is nothing about the mode in the docs - by providing second argument you set the log file (opened file object to which messages will be read).
So instead of:
bk = xlrd.open_openwork("fname","rb")
do:
bk = xlrd.open_workbook("fname")
这篇关于AttributeError:'模块'对象没有属性'open_openwork'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!