将电子表格列索引转换为字符序列

ext*_*.fx 0 ruby spreadsheet

如何获取字符序列,例如"AA"从列索引26

Zac*_*emp 9

这是一个递归哈希,它将为您处理索引:

index_hash = Hash.new {|hash,key| hash[key] = hash[key - 1].next }.merge({0 => "A"})
index_hash[26] #=> "AA"
Run Code Online (Sandbox Code Playgroud)

这里的关键是.next方法,当发送到字符串时,将返回按字母顺序排列的字符串,例如"CD".next #=> "CE".

你能澄清一下你的第一个问题吗?