不是普通的10-〉16进制转换
因为数字要从1开始而不是0
从其他Blog那里看到了一些算法
自己改了改
C#版本:
1
//10进制转换为Excel列的16进制
2
protected string GetCellColumnNumber(int iColumnCount)
3
{
4
iColumnCount--;
5
if ( iColumnCount < 26 )
6
{
7
return ((char)(iColumnCount+(int)'A')).ToString();
8
}
9
else
10
{
11
return ((char)(iColumnCount/26-1+(int)'A')).ToString() + ((char)(iColumnCount%26+(int)'A')).ToString();
12
}
13
}
2
3
4
5
6
7
8
9
10
11
12
13
vb版本:
1
Public Function GetCellColumnNumber(ByVal iColumnCount)
2
iColumnCount = iColumnCount - 1
3
If iColumnCount < 26 Then
4
GetCellColumnNumber = Chr(iColumnCount + Asc("A"))
5
Else
6
GetCellColumnNumber = Chr(iColumnCount / 26 - 1 + Asc("A")) + Chr(iColumnCount Mod 26 + Asc("A"))
7
End If
8
9
End Function
Public Function GetCellColumnNumber(ByVal iColumnCount)2
iColumnCount = iColumnCount - 13
If iColumnCount < 26 Then4
GetCellColumnNumber = Chr(iColumnCount + Asc("A"))5
Else6
GetCellColumnNumber = Chr(iColumnCount / 26 - 1 + Asc("A")) + Chr(iColumnCount Mod 26 + Asc("A"))7
End If8

9
End Function

浙公网安备 33010602011771号