python - openpyxl 行迭代器忽略 row_offset 参数?

标签 python python-3.x openpyxl

我正在尝试筛选大量无值(value)的数据,并且我想让用户有机会自己设置偏移量。代码最终看起来像这样:

master_rows = self.worksheet.iter_rows(row_offset=10000)

但是,在调用 next(master_rows)[0] 后,输出结果为:

RawCell(row=1, column='A', coordinate='A1', [...] )

基本上,偏移量似乎完全被忽略了,它总是从 0 开始。我做错了什么吗?

最佳答案

根据source code ,如果您不传递 range_string,则 iter_rows 将读取工作表中的所有列和行。换句话说,如果提供了range_stringrow_offset就会生效。

例如:

from openpyxl import load_workbook

wb = load_workbook('test.xlsx', use_iterators=True)
ws = wb.get_sheet_by_name('Sheet1')


# printing coordinates of all rows and cols
for row in ws.iter_rows(row_offset=2):
    for cell in row:
        print cell.coordinate


# printing coordinates from "A3:E5" range
for row in ws.iter_rows(range_string="A1:E3", row_offset=2):
    for cell in row:
        print cell.coordinate

关于python - openpyxl 行迭代器忽略 row_offset 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16820446/

相关文章:

python - 密文 Letter Freq Substitution : Comparing 2 dictionaries' dict keys by value and altering a text

python - 如何在 SQLAlchemy Alembic 迁移中更新记录?

python - openpyxl:在 load_workbook() 上给出错误

excel - 使用openpyxl在excel中查找图像和删除图像

python - 索引在 Pandas 中是如何工作的?

未收到 Internet 上的 Python 套接字

javascript - 如何使用 python 截取给定 url 的屏幕截图

python - 如何将特征的不确定性纳入机器学习算法?

python - 方法对象不可订阅

python - 使用 openPyxl 在 xlsx 中写入一整行