Search code examples
c#vstoexcel-2007

Column No to Column Letter in Excel/VSTO using C#


How to find column's name or header?

For example if i select column 5 in excel means i want the result as "E". How to get the alphabet or letter corresponding to column no.

Please help me with the code


Solution

  • What about using Application.ActiveCell.get_Address(true, true, Excel.AlReferenceStyle.xlA1, missing, missing) and then parse the result string or use a RegEx to get the column heading?

    I simply used:

    string location = Application.ActiveCell.get_Address(true, true, Excel.AlReferenceStyle.xlA1, missing, missing);
    string tokens = x.Split("$".ToCharArray());
    MessageBox.Show(String.Format("Column {0}", result[0]));