Excel Column Index To Column Letter - CSharp Office

CSharp examples for Office:Excel

Description

Excel Column Index To Column Letter

Demo Code


using Microsoft.Office.Interop.Excel;
using System;/*from   w ww  .ja  v a2  s.c  o  m*/

public class Main{
        public static string ColumnIndexToColumnLetter(int colIndex)
        {
            int div = colIndex;
            string colLetter = String.Empty;
            int mod = 0;

            while (div > 0)
            {
                mod = (div - 1) % 26;
                colLetter = (char)(65 + mod) + colLetter;
                div = (div - mod) / 26;
            }
            return colLetter;
        }
}

Related Tutorials