用过excel的都知道excel的列编号是这样的:
a b c .... z aa ab ac .... az ba bb bc .... yz za zb zc .... zz aaa aab aac ....
分别代表以下编号:
1 2 3 .... 26 27 28 29 .... 52 53 54 55 .... 676 677 678 679 .... 702 703 704 705 ....
请写个函数,完成从一个正整数到这种字符串之间的转换。
Public Function intcstr(ByVal ints As Integer) As String
Dim strs As String
strs = Nothing
Do While (ints Mod 26) <> 0 Or ints / 26 <> 0
If ints Mod 26 = 0 Then
ints = ints / 26 - 1
strs = Chr(96 + 26) & strs
Else
strs = Chr(96 + (ints Mod 26)) & strs
ints = Int(ints / 26)
End If
Loop
Return strs
End Function
Dim strs As String
strs = Nothing
Do While (ints Mod 26) <> 0 Or ints / 26 <> 0
If ints Mod 26 = 0 Then
ints = ints / 26 - 1
strs = Chr(96 + 26) & strs
Else
strs = Chr(96 + (ints Mod 26)) & strs
ints = Int(ints / 26)
End If
Loop
Return strs
End Function