我無法讓 openpyxl 遍歷我在 excel 筆記本中的所有行。
我試圖讓代碼列印特定列中的所有值,但是,它只是迭代 500 個專案并列印第一行 500 次。
到目前為止,這是我的代碼:
import pandas as pd
import openpyxl
import requests
wb = openpyxl.load_workbook('search.xlsx')
ws = wb['Results']
df = pd.read_excel (r'search.xls', sheet_name='Results')
for cell in ws:
y = ws.cell(row=2, column=1).hyperlink.target
print(y)
編輯:感謝@topsail,我得到了解決方案:
for row in ws.iter_rows(min_row=2):
print(row[0].hyperlink.target)
uj5u.com熱心網友回復:
import openpyxl
wb = openpyxl.load_workbook('Search.xlsx')
ws = wb['Result']
for row in ws.iter_rows(min_row=1):
if row[0].hyperlink is not None:
print(row[0].hyperlink.target)
else:
print(f"no hyperlink in cell {row[0].coordinate}")
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/486403.html
上一篇:在特定條件下提取子字串
