How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

前端 未结 30 2124
鱼传尺愫
鱼传尺愫 2020-11-22 00:35

How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.

Excel 2007 has a possible range o

30条回答
  •  难免孤独
    2020-11-22 00:47

    Coincise and elegant Ruby version:

    def col_name(col_idx)
        name = ""
        while col_idx>0
            mod     = (col_idx-1)%26
            name    = (65+mod).chr + name
            col_idx = ((col_idx-mod)/26).to_i
        end
        name
    end
    

提交回复
热议问题