JS:导出EXCEL,计算表头需要合并的单元格

要求导出这样形式的表格,需要列出哪些单元格需要合并再处理。

 

这里是计算一个月,以下JS:

 

// 进行所有表头的单元格合并
                let merges = [
                    'A1:A2', 'B1:B2', 'C1:C2', 'D1:D2', 'E1:E2'
                ];

                for (let i = 0; i < this.monthdays.length * 2; i += 2) {

                    let first;
                    let second;
                    let third;
                    let num = 5 + i; //我是从第五格开始的,所以是 5 + i,第一格开始就默认0
                    if (num / 26 <= 1) {
                        first = "";
                        second = String.fromCharCode(65 + num % 26)

                    } else {
                        first = String.fromCharCode(65 + parseInt(num / 26) - 1);
                        second = String.fromCharCode(65 + num % 26)
                    }
                    let letter1 = '' + first + second + '1';

                    if ((num + 1) % 26 == 0) first = String.fromCharCode(65 + parseInt(num / 26));

                    if ((num + 1) / 26 < 1) {
                        third = String.fromCharCode(65 + (num + 1) % 26);
                    } else {
                        third = String.fromCharCode(65 + (num + 1) % 26)
                    }
                    let letter2 = '' + first + third + '1';

                    merges = [...merges, '' + letter1 + ':' + letter2];

                }

 

你可能感兴趣的:(js)