2017-05-29 18 views
0

谷歌應用程序腳本的一部分我正在通過列值循環並將數據存儲在其位置中。我想從此操作中排除某些行,因爲我不希望這些列中的數據被覆蓋。如何從Google Apps腳本中排除某些列用於循環計算

// 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

而不是獲取單元格的值,您想獲取A1表示法並使用子字符串方法獲取該字母。那麼你的'如果'有條件檢查列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); 
    } 
} 
相關問題