<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta charset="utf-8" /> <title>索引转 Excel 列字母</title> </head> <body> </body> </html>
function excelColumnIndexAsLetter(n) { var cs = 'A'.charCodeAt(0); var len = 26; var s = ""; while (n >= 0) { s = String.fromCharCode(n % len + cs) + s; n = Math.floor(n / len) - 1; } return s; } [0, 26, 52, 999, 9999].forEach(n => { console.log(n, excelColumnIndexAsLetter(n)) })