Created
June 13, 2014 16:35
-
-
Save hkasera/90ad5daa22a6ac5657d8 to your computer and use it in GitHub Desktop.
A javascript code to get the excel cells array
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
var getCells = function (num) { | |
var cellArray = []; | |
for (var i = 0; i < num; ++i) { | |
cellArray.push(cellAt(i + 1)); | |
} | |
return cellArray; | |
}; | |
var cellAt = function (num) { | |
if (num <= 26) { | |
return String.fromCharCode(97 + num - 1); | |
} else { | |
return cellAt(Math.ceil(num / 26) - 1) + cellAt(num % 26 || 26); | |
} | |
}; | |
console.log(getCells(704)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment