谷歌应用程序脚本的一部分我正在处理循环列值并将数据存储在其位置。我想从此操作中排除某些行,因为我不希望覆盖这些列中的数据。
// save back the values from the editor sheet to the master data sheet
var lookUpTable = ss.getRangeByName("Editor_sheet_template!z_saveback_LookupTableOfCellsAndColumnsToSave");
var sourceCellAddress, sourceCellValue, targetCell, targetCellColumn;
// iterate through all rows in the lookup table
for (var cellRow = 1; cellRow <= lookUpTable.getHeight(); cellRow++) {
// save the value of the editor sheet cell listed in the lookup table to its
// corresponding column on the master data sheet
sourceCellAddress = lookUpTable.getCell(cellRow, /* column */ 1).getValue();
sourceCellValue = editorSheet.getRange(sourceCellAddress).getValue();
targetCellColumn = lookUpTable.getCell(cellRow, /* column */ 2).getValue();
if(targetCellColumn != 'A','D','E'){
Logger.log(targetCellColumn);
targetCell = masterDataSheet.getRange(targetCellRow, targetCellColumn);
targetCell.setValue(sourceCellValue);
}
}
答案 0 :(得分:0)
您想要获取A1表示法并使用子字符串方法来获取字母,而不是获取单元格的值。那你的&#39;如果&#39;有条件地检查A,D或E列应该有效。
// save back the values from the editor sheet to the master data sheet
var lookUpTable = ss.getRangeByName("Editor_sheet_template!z_saveback_LookupTableOfCellsAndColumnsToSave");
var sourceCellAddress, sourceCellValue, targetCell, targetCellColumn;
// iterate through all rows in the lookup table
for (var cellRow = 1; cellRow <= lookUpTable.getHeight(); cellRow++) {
// save the value of the editor sheet cell listed in the lookup table to its
// corresponding column on the master data sheet
sourceCellAddress = lookUpTable.getCell(cellRow, /* column */ 1).getValue();
sourceCellValue = editorSheet.getRange(sourceCellAddress).getValue();
targetCellColumn = lookUpTable.getCell(cellRow, /* column */ 2)
.getA1Notation().substring(0, 1); //this gets the first character of the A1 Notation which is the column letter
if(targetCellColumn != 'A','D','E'){
Logger.log(targetCellColumn);
targetCell = masterDataSheet.getRange(targetCellRow, targetCellColumn);
targetCell.setValue(sourceCellValue);
}
}