将数字转换为26个字符以外的字母

我正在为可映射的电子表格导出function创建一些客户端function。

我正在使用jQuery来管理列的排序顺序,但是每个列都像Excel电子表格一样排序,例如abcd e …… xyz aa ab ac ad等等

如何生成一个数字作为字母? 我应该定义一个固定的数组值吗? 或者有一种动态的方式来生成这个?

我想你正在寻找这样的东西

function colName(n) { var ordA = 'a'.charCodeAt(0); var ordZ = 'z'.charCodeAt(0); var len = ordZ - ordA + 1; var s = ""; while(n >= 0) { s = String.fromCharCode(n % len + ordA) + s; n = Math.floor(n / len) - 1; } return s; } // Example: for(n = 0; n < 125; n++) document.write(n + ":" + colName(n) + "
");

您可以使用这样的代码,假设numbers包含列的数字。 因此,在此代码之后,您将获得列的字符串名称:

 var letters = ['a', 'b', 'c', ..., 'z']; var numbers = [1, 2, 3, ...]; var columnNames = []; for(var i=0;i