Is it possible to make an HTML interface for a spreadsheet that doesn't run inside the spreadsheet? Basically I want to use the spreadsheet as a simple database.
I can't seem to find a way to do it in the documentation. I got this to work this way:
var ss = SpreadsheetApp.getActive();
function onOpen() {
var html = HtmlService.createHtmlOutputFromFile('index');
ss.show(html);
That opens my page automatically when I load the sheet, which is not a bad way to have it work, but I would rather run it from a separate page without having to know it is looking at a spreadsheet.
Also, this script doesn't work on mobile browsers which is an issue.
Is what I want to do possible currently? I have been looking at the documentation for a while without a clear answer.
I believe you will be wanting to deploy your script as a web app, rather than a "container-bound" script inside a spreadsheet.
As there will be no spreadsheet inherently associated with the web app, you would need to use the openById() method rather than getActive().
Related
I've created a small electron app that shows data from a google sheet via sheetrock.js to display table data. I've added a form that submits data to the google sheet with the help of triblondon's git
Now I'm trying to Implement a simple button on the electron app that will move populated rows from one sheet to another, creating a history. But for the life of me, I can't find a method of doing so that doesn't involve sending json data like the method above, writing to a cell and just doing formulas from there.
I'm just looking for a simpler, more direct approach by just invoking a function on the google script side (button + javascript probably).
Thanks for any help you can provide.
You can deploy your script as apps script. You will have use the public URL to be triggered by your button.
You can check everything about it on the Web Apps documentation.
I have several sheets set up to do a variety of things. I have a control sheet that looks to do things with these sheets, one of which would be to run a script that is in the target sheet (so not the control sheet). Is there a way in which I can get the control sheet to run the target sheet script?
For example, within Target Sheet "TargetOne", I've got attached code that runs "SubroutineOne".
function SubroutineOne() {
doSomething();
}
And in the Control Sheet I'd want to have something like this.
function ControlCode() {
setSomething();
run TargetSheet.SubroutineOne();
reportSomething();
}
Is there anyway of doing that? Thanks for reading.
There is no direct way to do this. If you want to call other Apps Script projects you should import them as libraries.
To do this, publish the Script on the Target Sheet and use it. Take a look at the documentation for instructions on how to do this.
If you have multiple sheets, this can become a very convoluted solution. You can have a single "master" sheets instead and use the openById(id) function to access the sheets you want to manipulate. That also allows you to modify all the sheets from one script.
Yet another solution is to deploy the Target Sheet as a Web App and add the code you wish to execute on the doPost() or doGet() calls. Be careful with this solution, since you will have to implement controls to avoid duplicate calls or calls by someone else.
Lastly, you could try to use the Apps Script API to directly make the call to execute it.
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.
Okay, so I'm working on a project for my job. We're using Google Drive to track work orders. Here's how it goes:
1) You fill out Request Form describing your work order.
2) Google scripts turns generates info from Request Form into Request Report and creates an Tracking Form
3) Personnel sign off on work order by filling out Tracking Form.
Pretty simple, but here's the trouble. I originally had all the Work Orders consolidated on one spreadsheet and you would input the Work Order's ID, but people kept making mistakes putting the correct # in so my boss wants each work order to have it's own separate Tracking Form. And once this new process is implemented, she wants me to touch it as little as possible.
Here's where the trouble comes in, I use a Tracking Form Template that has all the Google Script code in it, but the triggers can't copy over. I tried using the Request Form code to run the Tracking Form code, but it's way too complicated and prone to errors. I tried writing an onOpen code (that would create a menu for the Project Manager to authorize triggers) into the Template with the hope it would copy over, but that doesn't work either.
Can someone PLEASE tell me how to work around this problem?? Thanks!
Triggers that are created through the Resource menu won't stay in when a new copy of the spreadsheet / script is made. Think you'll want to create them programmatically, then they will (still need to run a function for it and authorize).
Some thing like...
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
ScriptApp.newTrigger('logDate').forSpreadsheet(ss).onFormSubmit().create();
}
function logDate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
s.getRange('A1').setValue(new Date());
};
Just need to clarify something and ask for a reference.
App Script Execute within the spreadsheet works fine with all the example.
but.
when appscript is deployed as webapp using scriptEditor -> publish -> Deploy as Webapp
most of the code in appscript is not working.
ex: using script editor create a form using builder create a doGet() function and show the form bind some function to button?
can anyone point me to a reference like opening the spreadsheet where the form is within and manipulating cell values.
can you please give me information where can i get reference for scripting on forms as webapps.
Thanks
The main difference between these 2 modes when accessing a spreadsheet is that the web app does not know the spreadsheet it is linked to unless you tell it explicitly, there is no such thing as 'active spreadsheet' or 'active sheet'.
So you should open the spreadsheet by ID (openById('long ID number') and choose the sheet by its name or index.
The other point, but I guess this one you'll find it obvious, is that UI functions attached to spreadsheet must end by "var doc = SpreadsheetApp.getActive();doc.show(app);" and web apps only by "return".
There are many examples on the web, some are available on Google Developpers or also here , hope you'll find some interesting ideas.
There are few more difference you might get in webapp like when you use it u might not able to use some classes that are limited to appscript only like: when you creating a page u cannot use Logger.log() instead you can use console.log() and see logs by inspect element > console > bottom.
web app allow us to use html, css, javascript to build web pages