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
Is there any method to get the number of rows and columns present in .xlsx sheet using openpyxl?
提问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