Copy a google script project from a Spreadsheet to another

后端 未结 4 1955
既然无缘
既然无缘 2021-01-14 03:35

I\'ve seen many answers about how to use scripts to copy sheets to another Spreadsheet in Google Spreadsheets, such as this copyTo method.

But now I have a big sprea

4条回答
  •  没有蜡笔的小新
    2021-01-14 04:17

    There appears to be no direct way to "Copy" the script from on spreadsheet to another But you can assign whatever triggers you want to the second spreadsheet from the script in the first one (or from anywhere actually) using Installable Triggers

    e.g. you have an onEdit(e) trigger in the first sheet that does some stuff, you can easily apply it to the second spreadsheet by using Script App like

    var ss = SpreadsheetApp.openById(secod_spreadsheet_id); //or whatever way you like
    ScriptApp.newTrigger('onEdit')  //or whatever its name is ...
      .forSpreadsheet(ss)
      .onEdit()  //or onCreate() or onChange()
      .create();
    

    and this will add the trigger to your second sheet, but you must read the restrictions and Limitaions for the installable triggers as they will always run on your account (see explaination in links)

    Last word,
    If you know previously that you are going to use many sheets you might want to make a Standalone script with all your triggers and assign installable triggers to your sheets

    Also note that these triggers can't be edited only removed and re-assigned from each sheet using a loop or something like that

    You might also want to check out This question

提交回复
热议问题