Convert an excel or spreadsheet column letter to its number in Pythonic fashion

前端 未结 17 1226
夕颜
夕颜 2020-12-09 04:18

Is there a more pythonic way of converting excel-style columns to numbers (starting with 1)?

Working code up to two letters:



        
17条回答
  •  轮回少年
    2020-12-09 04:48

    Coincise and elegant Ruby version:

    def col_num(col_name)
        col_name.split(//).inject(0) { |n, c| n * 26 + c.upcase.ord - "A".ord + 1 }
    end
    

提交回复
热议问题