ortense
3/30/2016 - 8:33 PM

Excel column name to number

Excel column name to number

/**
 * Excel column name to number
 * @param {string} str - excel column name for example 'A', 'AA' or 'AAA'.
 * @return {Number} Column number, start at 1.
 * @example
 * excel2num('A')   // 1
 * excel2num('Z')   // 26
 * excel2num('AA')  // 27
 * excel2num('AAA') // 703
 */

const excel2num = str => 
	[].reduce.call(str, (prev, cur) =>
		(prev * 26) + (cur.charCodeAt(0) - 64), 0)