把EXCEL列号数字变成字母

把Excel 列号数字变成字母

        private static string ToName(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());
        }

  

posted on 2014-11-07 10:18  苏上话  阅读(1889)  评论(0编辑  收藏  举报