I'm playing with google script. I want to execute getCursor() on the google script that's bounded to a google spreadsheet, but it seems it doesn't work. I can successfully open the google docs by DocumentApp.openbyId() on my google spreadsheet script, but getCursor() returns null although both google docs and google spreadsheet files are owned by me. Is it just impossible? or is there any way to make it work?
Thanks in advance.
No, you cannot use getCursor in a Sheet because it does not exist.
getCursor() is a method for the Document class from the Document Service.
No such method exists in Spreadsheet Service.
As an alternative, have you tried SpreadsheetApp.getActiveRange()?
Related
I'm trying to publish a sheet using Google Apps script and get its (published) URL.
The only solution I've found is this thread, however the proposed script publishes entire spreadsheet, not as suggested in the question, particular sheet. I'm not sure what syntax to use as fileId in
Drive.Revisions.update(resource, fileId, revisionId);
in order to publish only active sheet, not entire spreadsheet.
Unfortunately it is not possible to publish a single sheet with Google Apps Script/Drive API. This is a product limitation for Drive API, this request can be promoted for future development through here.
Also, you can't retrieve the URL from the published spreadsheet with the API but when the spreadsheet is published to the web, the URL follows a specific pattern, you can refer to this answer for more details.
The pattern to follow for a single sheet would be:
https://docs.google.com/spreadsheets/d/e/2PACX-SPREADSHEETID/pubhtml?gid=IDOFTHESHEET&single=true
You just can hide the other sheets in the spreadsheet
So if you publish only your desired one is shown.
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!
I have a task to update Apps Scripts linked to some Spreadsheets using Google REST APIs. I know how to update script if I have script Id, but the problem is that I have only spreadsheet Id, and I need to updated linked/bound script.
I didn't find any method in Apps Script REST API that would allow listing scripts linked to a spreadsheet https://developers.google.com/apps-script/api/reference/rest/
I also tried Google Drive REST APIs https://developers.google.com/drive/api/v2/reference/children/list and https://developers.google.com/drive/api/v2/reference/files/list with no luck.
Currently, it is not possible to retrieve the bound script id from the parent spreadsheet id. You can star(star on top left) these issues to prioritize these issues:
https://issuetracker.google.com/issues/111149037
https://issuetracker.google.com/issues/117105106
Depending on your use case, There's a workaround mentioned by Tanaike here
I have a google apps script that I use on the response sheet that results from a google form. I would like this script to always be available on any response sheet that gets created from a google form. I think I need to turn my script into an add-on, but I haven't found a simple explanation on how to do that.
I want to build a Google Doc Extension.
Google Spreadsheets has an onEdit trigger, Google Documents don't seem to: https://developers.google.com/apps-script/understanding_triggers
Is there a way for me to handle user input (typing) cleanly?
Not in Apps Script. If you write an app using the Drive API, you can use the Realtime API https://developers.google.com/drive/realtime/