Created
September 21, 2017 07:26
-
-
Save hyamamoto/bc54764fc13f809402502385e0e93f6c to your computer and use it in GitHub Desktop.
Converts an Excel-style column name to a number. (JavaScript / Python)
This file contains 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
// | |
// Convert an Excel-style column name to a number. | |
// | |
// Code: Hiroshi Yamamoto | |
function colNameToNum(name) { | |
var colNum = 0; | |
var pow = 1; | |
var i = name.length; | |
while(i--) { | |
var letter = name[i]; | |
colNum += (letter.charCodeAt(0) - 64) * pow; | |
pow *= 26; | |
} | |
return colNum; | |
} |
This file contains 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
# | |
# Convert an Excel-style column name to a number. | |
# | |
# Code: Chris West (http://cwestblog.com/2013/09/13/python-convert-excel-column-name-to-number/) | |
def colNameToNum(name): | |
pow = 1 | |
colNum = 0 | |
for letter in name[::-1]: | |
colNum += (int(letter, 36) -9) * pow | |
pow *= 26 | |
return colNum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment