代码段:通过索引获取对应的Excel列名; 索引从0开始,返回形如 A,B,C,...,Z,AA,AB,...,AZ,BA,...,ZZ,AAA,AAB,......

项目需要,今天写了个前端导出Excel的方法

/**
* 通过索引获取对应的Excel列名
* 索引从0开始,返回形如 A,B,C,...,Z,AA,AB,...,AZ,BA,...,ZZ,AAA,AAB,......
*/
var getExcelColumnName = function (index) {

var colName = '';

if (index >= 26) {
colName = getExcelColumnName(index / 26 - 1);
colName += String.fromCharCode(65 + index % 26);
} else {
colName += String.fromCharCode(65 + index);
}

return colName;
};
posted @ 2016-09-23 11:03  petunsecn  阅读(3394)  评论(0编辑  收藏  举报