WPS AI助手生成的能运行的代码,完整复制到AIRSCRIPT脚本编辑器中却不能运行?

WPS AI助手生成的能运行的代码完整复制到AIRSCRIPT脚本编辑器中却不能运行:

function Macro() {

const sheet = ActiveSheet;

const startRow = 4;

const endRow = 94;

const colH = "H";

const colI = "I";

let currentRow = startRow;

while (currentRow <= endRow) {

const cellH = sheet.Range(colH + currentRow);

const cellI = sheet.Range(colI + currentRow);

// 如果当前单元格为空,直接跳过

if (cellH.Value2 == null || cellH.Value2 === "") {

currentRow++;

continue;

}

// 初始化当前段的和

let segmentSum = 0;

let segmentStart = currentRow;

// 遍历当前段的所有数字

while (currentRow <= endRow &&

(sheet.Range(colH + currentRow).Value2 != null)) {

const value = parseFloat(sheet.Range(colH + currentRow).Value2);

if (!isNaN(value)) {

segmentSum += value;

}

currentRow++;

}

// 合并单元格并显示段的和

if (segmentStart < currentRow - 1) {

const mergeRange = sheet.Range(colI + segmentStart + ":" + colI + (currentRow - 1));

mergeRange.Merge();

mergeRange.Value2 = segmentSum;

} else {

// 单个单元格不需要合并

cellI.Value2 = segmentSum;

}

}

}

以上代码复制到AIRSCRIPT编辑器中运行没有反应。甚至在AIRSCRIPT编辑器中简单的I4单元格的值等于H4都不能正确输出。

天津
浏览 135
1
2
分享
2 +1
1 +1
全部评论