嗨,我只是拿起 xlrd。关于访问工作表和单元格属性,我指的是Xlrd Column
那里的代码显示。
for crange in thesheet.col_label_ranges:
rlo, rhi, clo, chi = crange
for rx in xrange(rlo, rhi):
for cx in xrange(clo, chi):
print "Column label at (rowx=%d, colx=%d) is %r" \
(rx, cx, thesheet.cell_value(rx, cx))
所以我想我只是测试从“数据”表中打印出单元格 A1,所以我开始复制上面的示例。
但是,当它完成时,它会在 col_label_ranges 处出错:
inBook = xlrd.open_workbook('T:/AzReporting/DraftUtilization.xls')
outBook = xlutils.copy.copy(inBook)
for crange in outBook.col_label_ranges:
rlo, rhi, clo, chi = crange
for rx in xrange(rlo, rhi):
for cx in xrange(clo, chi):
print "Column label at (rowx=%d, colx=%d) is %r" \
(rx, cx, outBook.cell_value(0, 0))
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: 'Workbook' object has no attribute 'col_label_ranges'
此外,如果我将 col_label_names 更改为工作表名称,它也会出错。这个例子我一定遗漏了一些东西。也许有更好的教程可以遵循?
for crange in outBook.Data: