Translate a column index into an Excel Column Name

前端 未结 15 2349
花落未央
花落未央 2020-11-27 20:41

Given a columns\' index, how can you get an Excel column name?

The problem is trickier than it sounds because it\'s not just base-26. The columns

15条回答
  •  天涯浪人
    2020-11-27 20:50

    In Ruby:

    class Fixnum
      def col_name
        quot = self/26
        (quot>0 ? (quot-1).col_name : "") + (self%26+65).chr
      end
    end
    
    puts 0.col_name # => "A"
    puts 51.col_name # => "AZ"
    

提交回复
热议问题