Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 仅在一列中使用OneEdit_Events_Google Apps Script_Google Sheets_Edit - Fatal编程技术网

Events 仅在一列中使用OneEdit

Events 仅在一列中使用OneEdit,events,google-apps-script,google-sheets,edit,Events,Google Apps Script,Google Sheets,Edit,我当前正在使用以下脚本: 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”中工作?如果您添加这些{},它应该适用于任何列: function onEdit(e) { //Set a

我当前正在使用以下脚本:

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”中工作?

如果您添加这些{},它应该适用于任何列:

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());
}

如果某列被编辑,则限制代码在Google工作表中运行。这将使用Apps脚本
onEdit()
reserved函数名,该函数名被触发在编辑事件上运行

获取范围的列号:

function onEdit(e) {//"e" receives the event object
  var range = e.range;//The range of cells edited

  var columnOfCellEdited = range.getColumn();//Get column number
  //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());
  };
};
另一个版本:

function onEdit(e) {//"e" receives the event object
  var range = e.range;//The range of cells edited

  var columnOfCellEdited = range.getColumn();//Get column number
  //Logger.log(columnOfCellEdited)


  if (columnOfCellEdited !== 3) {return;}// Halt the code if the column 
    //edited is not column C
    //Set a comment on the edited cell to indicate when it was changed.

  range.setNote('Laatst veranderd: ' + new Date());

};

您还可以尝试提取列索引。函数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 :(');
  }
}

这篇文章没有回答这个问题。