/// <summary>
/// 列号
/// </summary>
/// <param name="columnNum"></param>
/// <returns></returns>
public string GetNumber(int columnNum)
{
string columnName = string.Empty;
int i = columnNum / 26;
int j = columnNum % 26;
string k = string.Empty;
if (i == 0)//如果是26以内的就读取单个数据
{
columnName = GenerateLetter(j);
}
else//如果不是就递归计算
{
k = GenerateLetter(j);//先获得组合的最后一个字母
columnName = GetNumber(i) + k;//计算组合字母
}
return columnName;
}
/// <summary>
/// 获取单个列号
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public string GenerateLetter(int number)
{
string letter = string.Empty;
switch (number)
{
case 0: letter = "Z"; break;
case 1: letter = "A"; break;
case 2: letter = "B"; break;
case 3: letter = "C"; break;
case 4: letter = "D"; break;
case 5: letter = "E"; break;
case 6: letter = "F"; break;
case 7: letter = "G"; break;
case 8: letter = "H"; break;
case 9: letter = "I"; break;
case 10: letter = "J"; break;
case 11: letter = "K"; break;
case 12: letter = "L"; break;
case 13: letter = "M"; break;
case 14: letter = "N"; break;
case 15: letter = "O"; break;
case 16: letter = "P"; break;
case 17: letter = "Q"; break;
case 18: letter = "R"; break;
case 19: letter = "S"; break;
case 20: letter = "T"; break;
case 21: letter = "U"; break;
case 22: letter = "V"; break;
case 23: letter = "W"; break;
case 24: letter = "X"; break;
case 25: letter = "Y"; break;
default: return "";
}
return letter;
}