我试图弄清楚如果在sheet1中找到基于关键列的sheet2数据的行更新行。此外,如果未找到密钥,则添加新行。我已经想到迭代了sheet2的范围,但没有想到如何在sheet1中查找值。欢迎任何建议。 (我在这里更新了帖子。)
function getJulaUpdates2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("Franco-Jula");
var range1 = sheet1.getDataRange();
var values1 = range1.getValues()
var sheet2 = ss.getSheetByName("Jula-Alternatives");
var range2 = sheet2.getDataRange();
var values2 = range2.getValues()
// Iterate through sheet2
// Start at 1 to avoid header row
for (var i = 1; i < values2.length; i++) {
// Now loop through Values1 sheet
for (var x = 1; x < values1.length; x++) {
logthis = values2[i][0] + "," + values1[x][1];
if (values1[x][1] == values2[i][0]) {
values1[x][2] = values2[i][2]
values1[x][12] = values2[i][12]
values1[x][13] = values2[i][13]
Logger.log(logthis);
}
}
}
range1.setValues(values1)
}