Google apps script 如何使Google脚本为工作表的所有用户运行

Google apps script 如何使Google脚本为工作表的所有用户运行,google-apps-script,google-sheets,google-spreadsheet-api,Google Apps Script,Google Sheets,Google Spreadsheet Api,我构建了一个工作表,它使用下面的脚本根据列中的选择将行从一个选项卡移动到另一个选项卡。例如,如果此列中的选择更改为“关闭”,则整行将移动到“关闭”选项卡。如果更改为“死”,则会移动到“死”选项卡 但问题是,它只在我这样做时起作用,而在其他合作者更改单元格时不起作用。代码如下: function onEdit(e) { var ss = e.source; var activatedSheetName = ss.getActiveSheet().getName(); var activ

我构建了一个工作表,它使用下面的脚本根据列中的选择将行从一个选项卡移动到另一个选项卡。例如,如果此列中的选择更改为“关闭”,则整行将移动到“关闭”选项卡。如果更改为“死”,则会移动到“死”选项卡

但问题是,它只在我这样做时起作用,而在其他合作者更改单元格时不起作用。代码如下:

function onEdit(e) {
  var ss = e.source;
  var activatedSheetName = ss.getActiveSheet().getName();
  var activatedCell = ss.getActiveSelection();
  var activatedCellRow = activatedCell.getRow();
  var activatedCellColumn = activatedCell.getColumn();
  var activatedCellValue = activatedCell.getValue();

  var preclosingTrackerSheet = ss.getSheetByName("PRECLOSING"); // source sheet
  var closingTrackerSheet = ss.getSheetByName("CLOSING"); // target sheet
  var closedTrackerSheet = ss.getSheetByName("CLOSED FILES"); // target sheet
  var deadTrackerSheet = ss.getSheetByName("DEAD FILES"); // target sheet

  // if the value in column AG is "2-Closing", and you are in the PRECLOSING Sheet, MOVE the row to CLOSING sheet
  if (activatedSheetName == preclosingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "2-Closing") {
    // insert a new row at the second row of the target sheet
    closingTrackerSheet.insertRows(2,1);

    // copy the entire source row to the second row of target sheet
    var rangeToMove = preclosingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ preclosingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(closingTrackerSheet.getRange("A2"));

    // delete row from source sheet
    preclosingTrackerSheet.deleteRows(activatedCellRow,1);

  }

  // if the value in column AG is "CLOSED", and you are in the PRECLOSING Sheet, MOVE the row to CLOSED sheet
  if (activatedSheetName == preclosingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "3-Closed") {
    // insert a new row at the second row of the target sheet
    closedTrackerSheet.insertRows(2,1);
    // move the entire source row to the third row of target sheet
    var rangeToMove = preclosingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ preclosingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(closedTrackerSheet.getRange("A2"));

    // delete row from source sheet
    preclosingTrackerSheet.deleteRows(activatedCellRow,1);
  }


  // if the value in column AG is "DEAD", and you are in the PRECLOSING Sheet, MOVE the row to DEAD sheet
  if (activatedSheetName == preclosingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "x-Dead") {
    // insert a new row at the second row of the target sheet
    deadTrackerSheet.insertRows(2,1);
    // move the entire source row to the third row of target sheet
    var rangeToMove = preclosingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ preclosingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(deadTrackerSheet.getRange("A2"));

    // delete row from source sheet
    preclosingTrackerSheet.deleteRows(activatedCellRow,1);
  }

  // if the value in column AG is "PRECLOSING", and you are in the CLOSING Sheet, MOVE the row to PRECLOSING sheet
  if (activatedSheetName == closingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "1-Preclosing") {
    // insert a new row at the second row of the target sheet
    preclosingTrackerSheet.insertRows(2,1);

    // move the entire source row to the third row of target sheet
    var rangeToMove = closingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ closingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(preclosingTrackerSheet.getRange("A2"));

    // delete row from source sheet
    closingTrackerSheet.deleteRows(activatedCellRow,1);
  }

  // if the value in column AG is "CLOSED", and you are in the CLOSING Sheet, MOVE the row to CLOSED sheet
  if (activatedSheetName == closingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "3-Closed") {
    // insert a new row at the second row of the target sheet
    closedTrackerSheet.insertRows(2,1);
    // move the entire source row to the third row of target sheet
    var rangeToMove = closingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ closingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(closedTrackerSheet.getRange("A2"));

    // delete row from source sheet
    closingTrackerSheet.deleteRows(activatedCellRow,1);
  }


  // if the value in column AG is "DEAD", and you are in the CLOSING Sheet, MOVE the row to DEAD sheet
  if (activatedSheetName == closingTrackerSheet.getName() && activatedCellColumn == 33 && activatedCellValue == "x-Dead") {
    // insert a new row at the second row of the target sheet
    deadTrackerSheet.insertRows(2,1);
    // move the entire source row to the third row of target sheet
    var rangeToMove = closingTrackerSheet.getRange(/*startRow*/ activatedCellRow, /*startColumn*/ 1, /*numRows*/ 1, /*numColumns*/ closingTrackerSheet.getMaxColumns());
    rangeToMove.moveTo(deadTrackerSheet.getRange("A2"));

    // delete row from source sheet
    closingTrackerSheet.deleteRows(activatedCellRow,1);
  }  

}

如何告诉脚本在此工作表上为所有用户运行?

您是否关心该函数是作为编辑器运行,还是只按照您的方式运行

要像您一样运行,该函数需要在一个随您执行并用完处理配额的计算机上进行设置。然后,任何编辑器都可以激活它,而无需使用此路由对其进行授权。参考资料>>当前项目的触发器>>添加新-链接>>myFunction>>来自电子表格>>OneEdit>>保存

在这种情况下,建议将onEdit()重命名为您自己的函数名,以便在编辑时不会触发两次


要作为实际的编辑器而不是代表您运行,那么他们每个人都需要以某种方式首先对脚本进行授权。这可以通过单击自定义菜单项、单击侧栏加载项中的按钮、从加载项存储安装加载项或通过脚本编辑器手动运行函数来实现。然后,您现有的OneEdit()将随它们一起启动。

我希望每个可以编辑的人都能够对此列进行更改,并在更改时启动脚本。我如何制作一个他们只需点击一次的按钮(他们不是世界上最聪明的人),这样脚本就可以为他们工作?如果你不相信他们能够首先点击按钮,只需安装已安装的触发器。因此,我按照说明设置了触发器,但在使用其他用户的帐户进行测试后,这一排没有移动。您所指的“按钮”选项是什么?它是否在您的帐户下移动?您还必须更改
var ss=e.source
Yes Bryan,当我做出选择时,脚本正在按预期移动行。但是,当其他用户进行选择时,该行不会移动。