【问题标题】:Python 3.5.2 , openpyxl v 2.4.1 ,get_highest_row() , AttributeErrorPython 3.5.2,openpyxl v 2.4.1,get_highest_row(),AttributeError
【发布时间】:2019-06-06 14:55:25
【问题描述】:

我是 Python 新手,但在使用 openpyxl 模块打开 Excel 文件时遇到问题。我在 Windows 上的 Python 3.5.2 上运行 openpyxl V2.4.1。这里是一小部分我的代码。我收到以下错误。

这是我得到的错误:

请帮我解决这个问题,找到一种方法来获得工作表中的最大行数和列数。

如果我必须更改我的openpyxl 模块版本,请说明!

提前致谢。

WorkBook = openpyxl.load_workbook("G:\\Python_Created\\DS.xlsx")
#I have a Sheet named "Original" in my Excell Workbook
Sheet = WorkBook.get_sheet_by_name("Original")
Sheet.get_highest_row()

【问题讨论】:

  • 我认为openpyxl 的最新版本中没有这样的属性。使用SheetObj.max_rowSheetObj.max_column 将达到相同的目的。它们将分别返回最高行数和列数。

标签: python-3.x openpyxl attributeerror


【解决方案1】:

查看enigmas答案

wb = load_workbook(path, use_iterators=True)
sheet = wb.worksheets[0]

row_count = sheet.max_row
column_count = sheet.max_column

【讨论】:

    【解决方案2】:

    我认为该方法已贬值, 在较新版本的 openpyxl 库中 访问https://pypi.org/project/openpyxl/ 您可以使用此方法获取行数和列数

    #to get the row count
    sheet.max_row
    #to get the column count
    sheet.max_column
    

    【讨论】:

      猜你喜欢
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2019-02-04
      相关资源
      最近更新 更多