【问题标题】:How can I find the last non-empty column number of an Excel file using openpyxl?如何使用 openpyxl 找到 Excel 文件的最后一个非空列号?
【发布时间】:2021-12-31 06:44:14
【问题描述】:

如何使用 openpyxl 找到 Excel 文件的最后一个非空列号?

那么如果最后一列有数据是N列,我如何得到那个字母然后把它转换成一个数字呢?

【问题讨论】:

    标签: python excel openpyxl


    【解决方案1】:

    您需要 Worksheet.max_column,它是一个数字。

    from openpyxl import Workbook
    wb = Workbook()
    ws = wb.active
    ws['N3'] = 4
    ws.max_column # returns 14
    

    您可以使用以下方法转换列字母:

    from openpyxl.utils import get_column_letter, column_index_from_string
    column_index_from_string('N') # => 14
    get_column_letter(14) # => N
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      • 2018-06-10
      • 2016-10-13
      • 1970-01-01
      • 2020-07-21
      相关资源
      最近更新 更多