google-apps-scriptgoogle-apps-for-education

Looking to create a Google App Script that duplicates a complicated sheet? Ideas?


In the end, I want to make a script that creates a folder that has other folders in it with a bunch of copies of a custom data sheet our school is using for data analysis.
As of now, I have created a whole system of Google Data Sheets that are connected through the IMPORTRANGE feature of Google sheets that our school uses to compare data. I would like to implement this system in other schools and wanted to try and write a Google App Script to set it up.

I have a couple of questions:

  1. Is it possible to use a script to create a document is automatically set up to use the IMPORTRANGE feature to import data from another document?

  2. If I have a sheet set up already (the standard data sheet we use) that I want to make 400 copies of in different folders, do I have to code the script to generate this document from scratch? Do I code it to pull a copy from somewhere? What do you guys think?

Does this even seem like something that's possible? Thanks so much for your help guys! Brandon


Solution

    1. Sure. After you create the document, you'll just insert =IMPORTRANGE() using setFormula() or setFormulas(). You will have to manually grant permission for the sheet to import ranges the first time you open it, and any time after when you insert =IMPORTRANGE() with a reference to a new sheet, though.

    2. This is no problem either. You can use the Drive Service and makeCopy() to copy a file into a destination folder you specify.