简体   繁体   中英

How to run a standalone script on multiple google spreadsheets?

I have a standalone script that I need to run on Multiple Google Spreadsheets. I am able to assign a script to 1 spreadsheet using the following code:

function filter() {
  var ss = SpreadsheetApp.openById('ID');

How to assign this to multiple spreadsheets?

There are more than a single way to do it.

1) You can manually get the id's of the various spreadsheets and hard code the id's as an array in the stand alone script.

2) You can move all the spreadsheets required to a single folder and automate opening the folder and opening the files in the particular folder. For this, say, the folder containing the required spreadsheets is "All spreadsheets", then try out the following code.

function myfunction()
{ 
 var root = DriveApp.getFoldersByName("All spreadsheets");                                        
  while (root.hasNext())
  { 
   var folder = root.next();    //If the folder is available, get files in the folder
   var files = folder.getFiles();                                                                       
   while(files.hasNext())       //For each file,                                                                    
   { 
    var spreadsheet = SpreadsheetApp.open(files.next()); 
    required_function(spreadsheet);    //Call the required function
   }
  }
 }

Hope it helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM