数字转换成字母帮助类

C# 实现Excel(导出导入)非常实用的将数字转换成字母

   

/// <summary>
/// 需要转换的行或者列
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
private static string NunberToChar(int index)
{

index = index - 1;
if (index < 0) { throw new Exception("invalid parameter"); }

List<string> chars = new List<string>();
do
{
if (chars.Count > 0) index--;
chars.Insert(0, ((char)(index % 26 + (int)'A')).ToString());
index = (int)((index - index % 26) / 26);
} while (index > 0);

return String.Join(string.Empty, chars.ToArray());

}

 

猜你喜欢

转载自www.cnblogs.com/HF520134/p/9897951.html
今日推荐