Created
June 15, 2015 11:50
-
-
Save insin/19590f903e14940b3638 to your computer and use it in GitHub Desktop.
Get the 1-based index of an Excel cell given its column name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var baseCharCode = 'A'.charCodeAt(0) - 1 // Index is 1-based in Excel Interop | |
function excelColIndex(colName) { | |
var index = 0 | |
for (var i = 0, pow = colName.length - 1; i < colName.length; i++, pow--) { | |
index += Math.pow(26, pow) * (colName.charCodeAt(i) - baseCharCode) | |
} | |
return index | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment