Skip to content

Instantly share code, notes, and snippets.

@insin
Created June 15, 2015 11:50
Show Gist options
  • Save insin/19590f903e14940b3638 to your computer and use it in GitHub Desktop.
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
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