Excel Column Letter To Column Index - CSharp Office

CSharp examples for Office:Excel

Description

Excel Column Letter To Column Index

Demo Code


using Microsoft.Office.Interop.Excel;
using System;/* w  ww .  j a  v  a2  s .co m*/

public class Main{
        public static int ColumnLetterToColumnIndex(string columnLetter)
        {
            string columnLetterUpper = columnLetter.ToUpper();
            int sum = 0;
            for (int i = 0; i < columnLetterUpper.Length; i++)
            {
                sum *= 26;
                sum += (columnLetterUpper[i] - 'A' + 1);
            }
            return sum;
        }
}

Related Tutorials