我也有同样的问题。。。在
当我回来的时候,我很奇怪。在
这是密码(注'示例.xlsx'可以是任何填充了A1的电子表格。)import openpyxl
#D
arg1 = "A1"
'''Reads in a sheet'''
wb = openpyxl.load_workbook('example.xlsx')
ws = "".join(wb.get_sheet_names()[0])
sheet_ranges = wb[ws]
print(sheet_ranges[arg1].value)
结果是我们在这条线上失败了:
^{pr2}$
结果是:
TypeError:“Workbook”对象没有属性“getitem”
我怀疑它有一段时间是因为我加了一些魔术线。。。在
以下是一条线索:dir(openpyxl.doc)
['add', 'class', 'contains', 'delattr', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getitem', 'getnewargs', 'getslice', 'gt', 'hash', 'init', 'le', 'len', 'lt', 'mod', 'mul', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'rmod', 'rmul', 'setattr', 'sizeof', 'str', 'subclasshook', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
注意,这里有getitem的文档
塔达
答案是我通过debian存储库加载的openpyxl版本是1.5版。您可以使用以下代码发现这个可怕的事实:''' checks version of openpyxl '''
if str(openpyxl.__version__) <> "2.3.2":
#T if str(openpyxl.__version__) <> "1.5":
print "Trouble Ahead...this machine uses openpyx version "+str(openpyxl.__version__)
else:
print "Good to Go! This this machine uses openpyx openpyx version "+str(openpyxl.__version__)
当前版本是2.3.2。旧版本会让你哭泣。在
燧石