将整数单元格范围转换为Excel单元格范围

我在Ruby / Rails编码,我有一个单元格范围,一个例子是:

[0,1]..[0,3] with the convention [row, column]..[row..column] 

Excel使用单元格范围

 A2:A4 with the convention <column><row>:<column><row> 

我需要从前者转换到后者。 我所关心的主要是信件:

 A => 0, B => 1, C => 2, AA => 26 AB => 27 

我将如何去做呢?

我基本上需要做相反的事情:

使用ruby生成字母来表示数字?

VBA解决scheme

 Sub test_JohnLinux() MsgBox ColLet(4) & vbCrLf & InvColLet("D") End Sub 

从字母获取数字:

 Public Function InvColLet(x As String) As Long ActiveSheet.Cells(1, x).EntireColumn.Column End Function 

从数字中获得信件:

 Public Function ColLet(x As Integer) As String With ActiveSheet.Columns(x) ColLet = Left(.Address(False, False), InStr(.Address(False, False), ":") - 1) End With End Function 

Ruby解决scheme

信用必须去霍华德,我适应了这里的答案: https : //codegolf.stackexchange.com/questions/3971/generate-excel-column-name-from-index

 excel_column_ref =-> array_column_ref do ref = "A" array_column_ref.times{ ref.next! } ref end 

这返回一个proc。

用法excel_column_ref[26] = 'AA'