欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

数字转换成字母帮助类

程序员文章站 2024-02-06 20:58:52
C# 实现Excel(导出导入)非常实用的将数字转换成字母 /// /// 需要转换的行或者列 /// /// /// 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());

}