我正在尝试自动将数据从范围 (A2:A869) 移动到单元格 (G2),然后将输出 (G5) 复制到相应范围 (B2:B869)。简而言之,我想自动将单个值复制到单元格中,然后从另一个单元格复制该值,然后重复 869 次。我的代码看起来乱糟糟的。一定有比编写 869 次相同代码更简单的方法。
感谢您的帮助!
let selectedSheet = workbook.getActiveWorksheet();
// Paste to range G2 on selectedSheet from range A2 on selectedSheet
selectedSheet.getRange("G2").copyFrom(selectedSheet.getRange("A2"), ExcelScript.RangeCopyType.all, false, false);
// Paste to range B2 on selectedSheet from range G5 on selectedSheet
selectedSheet.getRange("B2").copyFrom(selectedSheet.getRange("G5"), ExcelScript.RangeCopyType.values, false, false);
// Paste to range G2 on selectedSheet from range A3 on selectedSheet
selectedSheet.getRange("G2").copyFrom(selectedSheet.getRange("A3"), ExcelScript.RangeCopyType.all, false, false);
// Paste to range B3 on selectedSheet from range G5 on selectedSheet
selectedSheet.getRange("B3").copyFrom(selectedSheet.getRange("G5"), ExcelScript.RangeCopyType.values, false, false);
}```