using System;
using System.Collections.Generic;
namespace Sp.Common
{
public class FunctionHelper
{
/// <summary>
/// 将数字转换为Excel列字母
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public static string NumberToLetter(int index)
{
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());
}
}
}