Python 是否有任何方法可以使用 openpyxl 获取 .xlsx 表中存在的行数和列数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35408339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:24:23  来源:igfitidea点击:

Is there any method to get the number of rows and columns present in .xlsx sheet using openpyxl?

pythonexcelopenpyxl

提问by Kulkarni Sachin

Is there any method to get the number of rows and columns present in .xlsx sheet using openpyxl ? In xlrd,

是否有任何方法可以使用 openpyxl 获取 .xlsx 表中存在的行数和列数?在 xlrd 中,

     sheet.ncols 
     sheet.nrows

would give the column and row count. Is there any such method in openpyxl ?

会给列和行计数。openpyxl 中有这样的方法吗?

回答by Alexander Craggs

Given a variable sheet, determining the number of rows and columns can be done in one of the following two ways:

给定一个变量sheet,可以通过以下两种方式之一确定行数和列数:

Version 1.x.x Syntax

版本 1.xx 语法

rows = sheet.nrows
columns = sheet.ncols

Version 0.x.x Syntax

版本 0.xx 语法

rows = sheet.max_row
columns = sheet.max_column