如何使用openpyxl普通工作簿查找列的最后一行? [英] How to find the last row in a column using openpyxl normal workbook?

查看:801
本文介绍了如何使用openpyxl普通工作簿查找列的最后一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用openpyxl将数据验证放入其中所有具有默认"值的行.但是要做到这一点,我需要知道有多少行.

I'm using openpyxl to put data validation to all rows that have "Default" in them. But to do that, I need to know how many rows there are.

如果我使用的是Iterable工作簿模式,我知道有一种方法可以做到,但是我也向工作簿中添加了新的工作表,并且以不可能的方式进行了迭代.

I know there is a way to do that if I were using Iterable workbook mode, but I also add a new sheet to the workbook and in the iterable mode that is not possible.

推荐答案

ws.max_row将为您提供工作表中的行数.

ws.max_row will give you the number of rows in a worksheet.

从openpyxl 2.4版本开始,您还可以访问各个行和列,并使用它们的长度来回答问题.

Since version openpyxl 2.4 you can also access individual rows and columns and use their length to answer the question.

len(ws['A'])

尽管值得注意的是,对于单列的数据验证,Excel使用1:1048576.

Though it's worth noting that for data validation for a single column Excel uses 1:1048576.

这篇关于如何使用openpyxl普通工作簿查找列的最后一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆