将电子表格列索引转换为字符序列 [英] Convert spreadsheet column index into character sequence
本文介绍了将电子表格列索引转换为字符序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从列索引 26
中获取字符序列,例如 "AA"
?
How can I the get character sequence, for example "AA"
from column index 26
?
推荐答案
这是一个递归散列,它将为您处理索引:
Here's a recursive hash that will handle indexing for you:
index_hash = Hash.new {|hash,key| hash[key] = hash[key - 1].next }.merge({0 => "A"})
index_hash[26] #=> "AA"
这里的关键是 .next
方法,当它发送到一个字符串时,将返回按字母顺序排列的字符串,例如"CD".next #=>CE"
.
The key here is the .next
method, which when sent to a string, will return the alphabetically following string, e.g. "CD".next #=> "CE"
.
你能澄清一下你的第一个问题吗?
Could you clarify your first question?
这篇关于将电子表格列索引转换为字符序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文