为什么iter_rows
总是说must be str, not int
?我只是想将lst
值传递给min_row
和max_row
。
from openpyxl import load_workbook
from itertools import islice
wb = load_workbook('xyz.xlsx')
ws1 = wb['Sheet1']
lst = ['2','2']
limit = 2
for i in islice(lst,limit):
row = ws1.iter_rows(min_row=i,max_row=i)
我已尝试将here发送给iter_rows
min_row
max_row
的想法,但我得到的错误与Worksheet object has no attribute
引用错误
line 509, in iter_rows
max_row += row_offset
答案 0 :(得分:1)
iter_rows
方法期望min_row
和max_row
输入参数是整数。所以试试这个:
from openpyxl import load_workbook
from itertools import islice
wb = load_workbook('xyz.xlsx')
ws1 = wb['Sheet1']
lst = [2,2]
limit = 2
for i in islice(lst,limit):
row = ws1.iter_rows(min_row=i,max_row=i)
注意:您可以通过使用命令iter_rows
或help(ws1.iter_rows)
查询其文档字符串来获取help(openpyxl.worksheet.worksheet.Worksheet.iter_rows)
方法的完整使用说明。在docstring中,您可以找到说明:
:param min_row: smallest row index (1-based index)
:type min_row: int
:param max_row: smallest row index (1-based index)
:type max_row: int