Convert spreadsheet number to column letter

前端 未结 13 1194
太阳男子
太阳男子 2020-11-30 05:47

I\'m looking for the opposite to this Q&A: Convert an excel or spreadsheet column letter to its number in Pythonic fashion.

or this one but in python How to conv

相关标签:
13条回答
  • 2020-11-30 06:29
    import gspread
    
    def letter2num(col_letter: str) -> int:
        row_num, col_num = gspread.utils.a1_to_rowcol(col_letter + '1')
        return col_num
    
    
    def num2letter(col_num: int) -> str:
        return gspread.utils.rowcol_to_a1(1, col_num)[:-1]
    
    
    # letter2num('D') => returns 4
    # num2letter(4) => returns 'D'
    
    0 讨论(0)
提交回复
热议问题