2016-01-12 17 views
0

我目前使用這個腳本:使用onEdit僅在一列

function onEdit(e) 

    // Set a comment on the edited cell to indicate when it was changed. 
    var range = e.range; 
    range.setNote('Laatst veranderd: ' + new Date()); 

什麼我需要補充所以這隻會在列「C」的工作?

回答

-2

如果添加這些{}應該對任何列工作:

function onEdit(e) { 
//Set a comment on the edited cell to indicate when it was changed. 
var range = e.range; 
range.setNote('Laatst veranderd: ' + new Date()); 
} 
+0

此信息未回答此問題。 –

1

獲取範圍內的列數:

function onEdit(e) { 
    var range = e.range; 
    var columnOfCellEdited = range.getColumn(); 
    //Logger.log(columnOfCellEdited) 

    if (columnOfCellEdited === 3) {// Column 3 is Column C 
    //Set a comment on the edited cell to indicate when it was changed. 
    range.setNote('Laatst veranderd: ' + new Date()); 
    }; 
}; 
0

你也可以嘗試提取列索引。函數getA1Notation()返回可用於解析列的單元格位置。

function onEdit(e){ 
    // Set a comment on the edited cell to indicate when it was changed. 
    var range = e.range; 
    var title = range.getA1Notation(); 
    var data = { 
    'bookName': 'Some book', 
    'whoAdded': 'Nick', 
    'whenAdded': new Date() 
}; 
var options = { 
    'method' : 'post', 
    'contentType': 'application/json', 
    // Convert the JavaScript object to a JSON string. 
    'payload' : JSON.stringify(data) 
}; 
    if(title.charAt(0) === 'B'){ 
     var result = UrlFetchApp.fetch('https://xxx.xxx', options); 
    }else{ 
    range.setNote('Failed to upload request :('); 
    } 
}