Google脚本函数onEdit()

时间:2018-06-29 17:33:45

标签: javascript google-apps-script

我正在学习如何将Google Apps脚本与Google表格一起使用,以及我如何使用以下脚本进行测试。它的基本功能是调用函数onEdit(),并在vCellOld中存储更改前的值,并在vCellNew中存储新值,然后显示带有这两个值的消息框。在tha之后,我试图将vCellOld存储在同一行的下一个单元格中,但无法正常工作。谁能帮我这个忙!?

function onEdit(e)
{
  //Store the old value
  var vCellOld = e.oldValue;
  //Store the new value
  var vCellNew = e.value;
  //Shows a message box with the old and new values
  Browser.msgBox("valor antigo: " + vCellOld + " valor novo: " + vCellNew);

  //HERE SHOULD STORE THE OLD VALUE ON THE NEXT RESPECTIVE CELL
  var nCell = e.range.Offset(0,1);
  ncell.setValue(vCellOld);

}

1 个答案:

答案 0 :(得分:0)

修复错误后,您说自己已解决,它对我有用。

function onEdit(e)
{
  //Store the old value
  var vCellOld = e.oldValue;
  //Store the new value
  var vCellNew = e.value;
  //Shows a message box with the old and new values
  Browser.msgBox("Old Value: " + vCellOld + " New Value: " + vCellNew);

  //HERE SHOULD STORE THE OLD VALUE ON THE NEXT RESPECTIVE CELL
  var nCell = e.range.offset(0,1);
  nCell.setValue(vCellOld);

}

通知

Notification

替换

Replacement