ExcelColumnIndex

public static int ExcelColumnIndex(this string columnName)
{
	int number = 0;
	int pow = 1;

	for (int i = columnName.Length - 1; i >= 0; i--)
	{
		number += (columnName[i] - 'A' + 1) * pow;
		pow *= 26;
	}

	return number;
}
Example:
int bIndex = "B".ExcelColumnIndex();

int amIndex = "AM".ExcelColumnIndex();

Description

Returns the excel column index from a column name

Details

Double click on the code to select all.

 

;