用的setArrayFormula 的方法
// 门店/部门编码列加公式
sheet1.setArrayFormula(startRow, 0, endRow-startRow, 1, '=IFERROR(INDEX(门店清单!A:B,MATCH(B' + (startRow+1) + ':B' + (endRow+1) + ',门店清单!B:B,0),1),"")');
// S-AF列加公式
let yearCol = 'S';
let price = 'F';
let strFormula = '';
//S列=前面12列的和
for (var i = 1; i <= 12; i++){
let col = Convert26(ConvertNum(yearCol) - i);
if (i==12){
strFormula += col + (startRow+1) + ':' + col + (endRow+1);
}else{
strFormula += col + (startRow+1) + ':' + col + (endRow+1) + '+';
}
}
sheet1.setArrayFormula(startRow, ConvertNum(yearCol)-1, endRow-startRow, 1, 'IFERROR(IF('+ strFormula + '=0,"",' + strFormula + '),"")');
// T-AF等于单价乘以对应的数量/面积
for (var i = 1; i <= 13; i++){
let col = Convert26(ConvertNum(yearCol) + i - 13);
let strFormula = col + (startRow+1) + ':' + col + (endRow+1) + '*' + price + (startRow+1) + ':' + price + (endRow+1);
sheet1.setArrayFormula(startRow, ConvertNum(yearCol)-1+i, endRow-startRow, 1, 'IFERROR(IF('+ strFormula + '=0,"",' + strFormula + '),"")');
} |