NPOI根据列索引获取列名

public static string ConvertColumnIndexToColumnName(int index)

        {

            index = index + 1;

            int system = 26;

            char[] digArray = new char[100];

            int i = 0;

            while (index > 0)

            {

                int mod = index % system;

                if (mod == 0)

                    mod = system;

                digArray[i++] = (char)(mod - 1 + 'A');

                index = (index - 1) / 26;

            }

            StringBuilder sb = new StringBuilder(i);

            for (int j = i - 1; j >= 0; j--)

            {

                sb.Append(digArray[j]);

            }

            return sb.ToString();

        }

 

posted @ 2016-07-31 10:52  飘....  阅读(1823)  评论(0编辑  收藏  举报