1
嗨,我只是拿起xlrd。關於訪問表和單元格屬性,我指Xlrd Columnpython xlrd - 從工作表檢索列索引
從那裏的代碼顯示。
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: