Created
August 21, 2019 21:10
-
-
Save johnvilsack/67c75bd94ca08d8d9039c7f87acfe5c2 to your computer and use it in GitHub Desktop.
GAS: Column to A1 and Back Again
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
// Fixes SMALL oversight of not being able to work with A1 notation | |
function columnToLetter(column) | |
{ | |
var temp, letter = ''; | |
while (column > 0) | |
{ | |
temp = (column - 1) % 26; | |
letter = String.fromCharCode(temp + 65) + letter; | |
column = (column - temp - 1) / 26; | |
} | |
return letter; | |
} | |
function letterToColumn(letter) | |
{ | |
var column = 0, length = letter.length; | |
for (var i = 0; i < length; i++) | |
{ | |
column += (letter.charCodeAt(i) - 64) * Math.pow(26, length - i - 1); | |
} | |
return column; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment