带有列号的Google Scripts IF语句

时间:2017-09-29 15:17:19

标签: google-apps-script

Google Scripts的新功能,似乎管理得很好,但遇到了问题..

我有一个触发器'编辑'只有当用户编辑了第3列中的单元格时,我才想运行它。使用下面的代码,无论编辑哪个列,它都会运行。希望有人能提供帮助。感谢

 function sendNotification2() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = ss.getActiveCell().getA1Notation();
var row = ss.getActiveRange().getRow();
var column = ss.getActiveRange().getColumn();

 if(column = 3){ 
Browser.msgBox('you edited column 3!', Browser.Buttons.OK);
 }
};

1 个答案:

答案 0 :(得分:0)

替换为:

如果(柱= 3)

这是作业

使用此:

如果(列== 3)

经过进一步审核,我也会尝试这一点。

function sendNotification2() 
{
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getActiveSheet();
 var cell = sheet.getActiveCell();
 var row = cell.getRow();
 var column = cell.getColumn();
 if(column == 3)
 { 
  var ui=HtmlService.createHtmlOutput('column3.');
  SpreadsheetApp.getUi().showModelessDialog(ui, 'You Edited')
 }
}

这是另一种方法:

function onEdit(e) 
{
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getActiveSheet();
 var cell = sheet.getActiveCell();
 var row = cell.getRow();
 var column = cell.getColumn();
 if(column == 3)
 { 
  var s=Utilities.formatString('You edited column %s row %s oldvalue = %s newvalue = %s ', column, row, e.oldValue, e.value);
  var ui=HtmlService.createHtmlOutput(s);
  SpreadsheetApp.getUi().showModelessDialog(ui, 'Column 3 Edits')
 }
}