Is there any way to access the documentation for functions directly from the Google Apps Script editor? I'd like to do so either as I'm typing the function name, as well as when looking at existing code.
For example, when examining the following line of code:
var ss = SpreadsheetApp.getActiveSpreadsheet();
I'd like to be able to hover over or right click getActiveSpreadsheet(), and be shown the appropriate documentation that describes this function's behavior.
Unfortunately the Apps Script code editor doesn't have this feature, but you can file a feature request to have it added.
Related
Iv'e written a custom google sheet function using Google Apps Script, and i would like to share it with another spreadsheet user, but i do not want to share the functions source code.
I've converted the Google Apps Script to a project, but now i have no idea how to link the project back to my sheet, so the function will work again.
I also do not want to publish the AddIn to the marketplace.
Test As Addin also doesn't work, the sheet is opened in a new tab, but the cells with the custom function says #NAME?.
What am i missing?
Explanation / issues:
The error #NAME? indicates that you are trying to use a function
that does not exist. As you also mentioned, this function does not
belong to the active spreadsheet but on a different project.
Unfortunately, it is not possible to share a custom function with other spreadsheets directly.
Possible Workarounds:
You can create an add-on.
Another workaround solution would be to create a library. That is a great alternative and the documentation is quite straightforward.
Related:
Creating add ons in Google Apps Script
How to call library function as custom function from spreadsheet formula?
Brand new at this.
I thought the following code in Google Apps Script would simply open a sheet in another window. But nothing happened. Nothing.
Here's my code:
function OpenaSheet() {
SpreadsheetApp.openByUrl('https://docs---------Blanked out on purpose-------------')
}
The SpreadsheetApp openByUrl(url) was meant to access your google spreadsheet as shown in the docs.
Another way to access your gsheet is by openById. So openByUrl doesn't literally mean it will open a provided Url but instead a means to access the spreadsheet. Check this SO post for that purpose.
I am going through the book Google Sheets Programming with Google Apps Script by Michael Maguire and I am trying to run the following Hello World-type function:
function sayHelloAlert() {
// Declare a string literal variable.
var greeting = 'Hello world!',
ui = SpreadsheetApp.getUi();
// Display a message dialog with the greeting
//(visible from the containing spreadsheet).
// Older versions of Sheets used Browser.msgBox()
ui.alert(greeting);
}
When I select this function and try to run it, it returns an error: The api method 'getUi' is only available in the new version of Google Sheets. (line 3, file "Code"). How can I not be using the new version of Google Sheets? I have only just started using Google Script in the past week. How do I verify which version I am using?
You have to create a new spreadsheet in Sheets and from the Sheets menu go to Tools --> Script Editor. You cannot access scripts.google.com directly.
For spreadsheet use, I would use the Browser Class:
Google Documentation - Browser Class
If the spreadsheet is only going to be used by you, it's not a problem using .getUi() as long as you are using the new sheets. But if other users are running the code, and are using the old Sheets, they would get an error.
I don't see any method in the Spreadsheet Class for getting the version of the users Google Sheet using code. I don't know if the advanced Drive Service has that information in the metadata of the file. But, if Browser Class or HTML Service can be used in both old and new sheets, then I'd just use one of those two.
I know it's a long shot however, do you know if it is possible to attach a script to a spreadsheet you create in a script?
pseudo code version would be
function create_spreadsheet
new spreadsheet = ... creates spreadsheet
new spreadsheet = ... fills with appropriate formatting
-Need help part is -
new spreadsheet add script = ... Attach Following script to the new spreadsheet.
-Need help part is -
You can use the AppsScript REST API (aka "advanced API") to programmatically manage AppsScript projects. See https://developers.google.com/apps-script/api/how-tos/manage-projects This includes the ability to create "bound" projects (i.e., bound to a specific Sheet) and upload new content to that project's files.
However, to use the REST API from AppsScript code you'll need to enable the "advanced API". See https://developers.google.com/apps-script/guides/services/advanced.
I have not gotten to try it yet, but rather than creating a spreadsheet you could copy a public version of a spreadsheet that includes the script.
I'm trying to automate the creation of a spreadsheet in Google. I'm able to create and edit the spreadsheet just fine. The problem I'm having is opening.
function CoS(){
var Sheet = SSheet.getActiveSheet();
var bill = Sheet.getActiveCell().getValues();
var nSheet = NewCoS(bill);
var file = DocsList.getFileById(nSheet.getId());
var ss = SpreadsheetApp.open(file); //Doesn't work the way I need it to
Browser.msgBox(ss.getName());
}
I've tryed .openByUrl and .openById. In the documentation I read that these are for opening in the background but .open seems to do the same thing. However the documentation doesn't state explicitly that that is what it's meant for. Browser.msgbox() works so it seems logical that the file is getting opened in the background. I also can't find anything like Spreadsheet.visiblity() or Spreadsheet.show() as I would expect in excel.
I've even looked in other libraries like Drive and DocsList.
Is there a way to open my spreadsheet through script so that the user can see it?
Opening a spreadsheet means "get read and write access to that sheet", it does not mean "show this spreadsheet in my browser".
If you need to get such a functionality then use a href link (in HTMLService) or an anchor widget (in UiApp) that will redirect you to another browser tab/window with that spreadsheet.
Note also that there is no SpreadsheetApp.open method, use the autocompletion in the script editor to be sure about available methods in Google Apps Script.