AttributeError: 'Workbook' object has no attribute 'iter_rows'
时间: 2023-09-29 08:08:36 浏览: 104
This error occurs when trying to use the `iter_rows` method on a `Workbook` object in Python.
The `iter_rows` method is used to iterate over rows in a worksheet within the workbook. However, it is not available on the `Workbook` object itself, only on a specific worksheet object.
To fix this error, you need to first select the worksheet you want to iterate over using the `active` or `get_sheet_by_name` method on the `Workbook` object. Then, you can use the `iter_rows` method on the selected worksheet object.
Here's an example:
```
import openpyxl
# Load the workbook
wb = openpyxl.load_workbook('my_excel_file.xlsx')
# Select the worksheet you want to iterate over
ws = wb.active
# Iterate over the rows in the worksheet
for row in ws.iter_rows():
# Do something with each row
print(row)
```