/**
* 根据单元格列号,计算表格列名 如 27列 = AA
* 2022-11-07 目前支持范围 A-ZZ
* @param {} cellCode
*/
function CalculateExcelcellName(cellCode)
{
var Colum = "";
//A-Z之间的ASCII码值 为 65-90
if(cellCode < 65 && cellCode >740)
return "";
if(cellCode >= 65 && cellCode <= 90){
Colum = String.fromCharCode(Number(cellCode));
return Colum;
}
var tmp = parseInt(cellCode - 65);
//firstcode 26进1
var firstCode = parseInt(tmp/26 + 65);
// console.log("firstCode:" + firstCode);
var lastCode = parseInt(tmp % 26 + 65);
console.log("lastcode:" + lastCode);
if(lastCode > 90){
lastCode -= 26;
}
Colum = String.fromCharCode(Number(firstCode));
console.log("firstCode--Colum:" + Colum);
Colum += String.fromCharCode(Number(lastCode));
console.log("Colum:" + Colum);
return Colum;
}
例:
CalculateExcelcellName(70);
'F'
CalculateExcelcellName(91);
'BA'
CalculateExcelcellName(740);
'ZZ'