当G传递给下面的代码时,它返回1而不是7.有人能指出我正确的方向吗?我正在尝试从列字母中获取Excel列索引。谢谢
Public Function ColLetterToColIndex(colLetter As String) As Integer
colLetter = colLetter.ToUpper()
Dim sum As Integer = 0
For i As Integer = 0 To colLetter.Length - 1
sum *= 26
Dim charA As Integer = Char.GetNumericValue("A")
Dim charColLetter As Integer = Char.GetNumericValue(colLetter(i))
sum += (charColLetter - charA) + 1
Next
Return sum
End Function
答案 0 :(得分:0)
试试这个(而不是GetNumericValue):
Dim charA As Integer = Asc("A")
Dim charColLetter As Integer = Asc(colLetter)
其他一切都可以保持不变。