[英]How do I iterate through a column using openpyxl and get the values of specific cells?
[英]How do I iterate through cells in a specific column using openpyxl 1.6
我目前正在使用Python 2.7,到目前為止已經能夠實現這一目標。 我需要在D列中打印單元格的值,直到excel表格的最大行。
wb = openpyxl.load_workbook(filename)
sheet = wb.get_sheet_by_name('Something')
for row in range(2, sheet.get_highest_row()):
bla=str(row)
status = sheet['D' + bla].value()
print status
這給了追溯
Traceback (most recent call last):
File "ExcelAnalysis.py", line 25, in <module>
status = sheet['D' + bla].value()
TypeError: 'Worksheet' object has no attribute '__getitem__'
我懷疑你使用的是過時版本的openpyxl
,請更新它:
pip install --upgrade openpyxl
而且,你不應該稱之為value
,它是一種財產:
status = sheet['D' + bla].value
我認為這是一種非常原始且不是非常優化的方式,但我得到了答案。
for cow in range(1, sheet.get_highest_row()):
status = sheet.cell(row=cow, column=3).value
請,如果有人可以,幫我改進它。 非常感謝你提前。
在此頁面上查看更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.