使用Python 3.6.x和xlrd库从Excel表格中读取单元格数据

3
这是我的样例代码。
import xlrd

file_location=("/home/deep/Desktop/Book1.xlsx")
workbook=xlrd.open_workbook(file_location)
sheet=workbook.sheet_by_index(0)
first=sheet.cell_value(1,1)

print(first)

但是我在这方面遇到了以下错误:
跟踪(最近的调用最先): 文件“/home/deep/ws/xcx.py”,第6行, workbook=xlrd.workbook(file_location) 属性错误:模块“xlrd”没有属性“open_workbook”
2个回答

1
根据您的错误信息,
Traceback (most recent call last): File "/home/deep/ws/xcx.py", line 6, in workbook=xlrd.workbook(file_location) AttributeError: module'xlrd' has no attribute 'open_workbook'

我猜您打错了一个字,它应该是:

workbook=xlrd.workbook(file_location)

它一定是:

workbook=xlrd.open_workbook(file_location)

xlrd 对我来说很好用!!我刚试过了!!


0

open_workbook 是完全可以使用的。但在最后一行,你应该使用:

first=sheet.cell(1,1) 
print(first.value)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接