I'm new to this google script thing so I'm not sure what should I do with this. So, I'm working with 8 folders with files with the same structure and scripts. So, when I opened my projects on the Google App Script. I currently have 178 projects. I just want to ask if the picture below is a normal thing or is there a way for me to minimize it since some of it has the same scripts? Can I use one project in multiple sheets?
As you can see in the picture below, I do have 8 ARCS_AP_ROWS since I duplicate the spreadsheet 8 times. The scripts in there were all the same.
The reason you are having a separate script for each spreadsheet is because you created container-bound scripts.
What are container-bound scripts?
According to the Apps Script documentation:
A script is bound to a Google Sheets, Docs, Slides, or Forms file if it was created from that document rather than as a standalone script. The file a bound script is attached to is referred to as a "container". Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.
TL;DR - they're scripts created for one particular document.
So even though you essentially have the same script, the document on which the script acts is different.
What you can do
Create a standalone script and use SpreadsheetApp.openById("SPREADSHEET_ID") and pass the SPREADSHEET_ID parameter in order to open a specific spreadsheet;
Create an add-on.
Reference
Container-bound Scripts;
Standalone Scripts;
Apps Script SpreadsheetApp Class - openById(id);
Google Workspace Add-ons.
Related
I have a google sheets which is linked to a form and a google scripts that was created in the menu of google sheets. This script runs fine and I use it to format the data. However, I have another script which I created from the google developer console, which sends and receives data from a website. I need this second script to get the value of a cell in the google sheets.
How can I link this second form to the google sheets while keeping the script already linked to the sheets?
When looking at responses to other questions they seem to be about individual sheets in a set so just to clarify, when referring to google sheets I mean the whole google sheets document. I only have one sheet anyways.
If it helps: The script I want to add acts a bit like a server and is being deployed by google scripts while the script that is already linked is only run when I call it on the sheets.
There is not way of attaching a standalone script to a document making it a bound script (which is the actual terminology for the script linked the the document).
The simplest way would be to copy-paste the code to the other script. You can deploy the bounded script.
If you really need more than one project for whatever reason, you can enable the Apps Script API and use projects.create (read reference) to create another one. If you don't know what this means, you probably shouldn't use it as it's finicky at best.
I found a solution which was to link the script to the google sheets using
var ss = SpreadsheetApp.openById("SHEET_ID_HERE");
I can then use ss.getActiveSheet().getRange().getValue();
and other funtions.
Thanks for the help!
Is there a way for a google spreadsheet to fetch and copy the scripts from a different spreadsheet?
I have a file that users make an individual version for them to use. The file also includes various scripts, including one that updates the sheets and formulas in case the master file changes.
However, I haven't found any way in which to update the scripts themselves. I can't deploy the script as an add-on because that function is blocked in my company.
Is there any other way to do it?
If you want to copy/update scripts in a sheet you can try using the Apps Script API.
I have a Google Sheets script that's bound to a specific doc. Basically it takes the results of certain cells, then it used these values in doc.
I have multiple Sheets I'd like to "attach" to this script. All the other Sheets have the exact same tabs and cell names, etc.
Is there a way to turn that bound script to a standalone script, then attach them to the other Sheets?
You cannot unbind a bound script:
The file a bound script is attached to is referred to as a "container". Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.
To use the functionality you've created, you'll want to export the bound script as a library and import it in the other spreadsheets' script editors. You may also have to do some tweaks to get any UI alterations
Note that an installed library will not automatically update the used version, so if you make changes to your library source and save a new version, you'll have to go through all the spreadsheets that reference it and update the library version.
The alternative to a library is to go through the process to publish your script as an add-on. This will let you redeploy your changes without needing to go through every single spreadsheet.
I have developed few scripts in a given project attached to a spreadsheet (ie that I first created my spreadsheet, and then created the project with the menu Tools>Script editor).
Now my question is:
how can I save that project so that it can be used on other spreadsheets?
how do I select in a given spreadsheet which script project I want to use?
From this Google documentation page I can't see any solution.
To have a script that's not bound to any document, look into making a standalone script.
If you want to use a script in multiple documents, you'll need to publish it as a library.
I created a google app script that is bound to google sheet later I moved it as standalone script inside a google drive folder. I thought I will be able to reuse it across multiple sheet. Now I am not able to find any way to run standalone script inside my google sheets. Please suggest.
From your standalone script you can access your spreadsheets and work this way with your files.
Use something like this to get a set of spreadsheets (pseudocode)
var ssList = ['...','...']
for each element in ssList do:
SpreadsheetApp.openById(ssList[element]);
Then you can reuse your code and access multiple spreadsheets.
But it is not possible to access multiple apps script files, only one file is bound to your spreadsheet.