C# 實現Excel(導出導入)非常實用的將數字轉換成字母 /// <summary> /// 需要轉換的行或者列 /// </summary> /// <param name="index"></param> /// <returns></returns> private static strin ...
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());
}