Skip to content

Instantly share code, notes, and snippets.

@hkasera
Created June 13, 2014 16:35
Show Gist options
  • Save hkasera/90ad5daa22a6ac5657d8 to your computer and use it in GitHub Desktop.
Save hkasera/90ad5daa22a6ac5657d8 to your computer and use it in GitHub Desktop.
A javascript code to get the excel cells array
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