Here is what I'm trying to do:
Embed a Google spreadsheet in my website in multiple locations. For registered users, I want to show all the data in the spreadsheet. For unregistered users, I want to hide key numbers.
I have a spreadsheet with a custom function called blackOut(). I've put the blackOut function in all of the cells with sensitive data. All blackOut() need to do is this:
function blackOut(e) {
var is registered = ??
if (is_registered) return e;
else return "";
}
But I cant find any way to 'pass' any variables from my website to the function, so I haven't been able to make it work.
Here's my environment:
In PHP I'm using cURL to get the spreadsheet's embed code from this URL:
https://docs.google.com/spreadsheet/pub?key=[spreadsheet ID]&output=html&widget=true
then I'm doing a few str_replace functions to make the JS and CSS work.
Here's what I've tried:
using window.location in my function (doesn't work. Google doesn't let you access window)
passing a javascript variable in globally (in JS global variables are technically attached to the window object)
using SpreadsheetApp.getActiveSpreadsheet().getURL() (just returns the URL for the spreadsheet, not the one that existed in the http request)
looking through all of the available objects in Google Code
My Ideal Solution:
It would be great if I could just add '&blackout=true' to the URL, and pass that into blackOut() in the google script. I've looked around a lot, and I don't think it's possible.
I've looked at these links:
How can I get URL parameters passed to a Google Spreadsheet using Google Apps Script?
Alternative to global variables
GAS: Problems in using global variables in functions
Any ideas on how I can get this to work?
Maybe i'm understanding your question wrong, but am i to understand that you are not using a iframe or viewing the sheet directly? You are using a published url and from there you get your data. You already do some custom conversion to the HTML (so you have the knowledge and tools to edit your data/html yourself).
Could you go a small step further and create the whole html table yourself?
Then you could use the query functionality of google spreadsheets (url query parameters).
This way you could validate the users from your site and do two different data query's.
One with all the columns, one without some columns.
For example see: http://acrl.ala.org/techconnect/?p=4001
For the google language reference: https://developers.google.com/chart/interactive/docs/querylanguage
Related
This question already has an answer here:
Google Spreadsheets: Show Document URL in cell. Possible?
(1 answer)
Closed last year.
Why?
I am trying to send information about spreadsheets to a server, using the =IMPORTHTML() method. And then returning the appropriate response to the spreadsheet (kind of like an API). I don't want to have to mess with log in data so I am going to use the URL of the spreadsheet for a primary key in a data base.
I know they could just copy and paste their information into a cell and I could use that. But I want this to be ready out of the box.
This spreadsheet is intended for unexperienced users, and potentially ones on restricted accounts. And so vanilla is best here. But if that is impossible, just let me know.
Thanks!
Use getUrl() method of Class Spreadsheet.
Example:
function getUrl(){
return SpreadsheetApp.getActiveSpreadsheet().getUrl();
}
You might use it as a custom function, =getUrl(), among other ways.
Resources
https://developers.google.com/apps-script/guides/sheets
https://developers.google.com/apps-script/guides/sheets/functions
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#geturl
I need to generate/display an HTML page (or iframe or how-ever it could be done on demand from an apps script) from a Google sheet using Apps Scripts. It looks like there's an htmlForms service for Docs, but I can't find the equivalent for sheets.
My goal is to provide a menu item that can parse my data (already done) then call up another page where knockOutJs will be used to transfer the generated JSON into an html preview. Right now my script generates the JSON and if I could use something like
I'm using HtmlService.createHtmlOutputFromFile() to generate the HTML but FormApp.getUi() isn't valid in this context and neither is
You must get a reference to the current SpreadSheet (not the "ActiveSheet", but the entire SpreadSheet object) then call show() passing in your object from createHtmlOutputFromFile() or similar method.
var htmlRes HtmlService.createHtmlOutputFromFile('YourProjectHtmlFile');
SpreadsheetApp.getActiveSpreadsheet().show(htmlRes);
Is there an easy way of making a call from one Google Apps script to a function in another?
I'm writing two scripts, one which should use functions from the other. I want the two to have different sharing permissions, however, so I don't want to put them in the same project.
I can't seem to find any "require Xxx.gs" type function in the documentation.
I found this:
Call functions from another "class" / file
But I get "xxx function not found" errors if I try to call a function from a different file.
As Corey mentioned in the post you refer to you need to use libraries to do what you want.
You can not use functions from another project in a project (but you can of course use any function from different script files inside a project)
Besides libraries, if you actually want to keep the projects separate you can publish a service url and use parameters to call it from the other script with urlFetch, as in myserviceurl?call=myfunction¶m1=x
I've created a function in Google Script Editor that appends a row in Google Spreadsheet. Values being passed as parameters.
Now, what I want to do is, call this function in my HTML page (built using UI Services, not HTML Services) and pass the values to be stored from this page. I cannot find a way. Pls help?
At the time you asked this question, the documentation was not very rich. It has improved considerably, and there are examples provided that are close to what you want to do.
With the UI Service, the way you would accomplish this would be by using a handler function, either client-side or server-side, which would be triggered by a button click (for example), and handle the submission of a "form" (a set of input text areas, etc.). The handler would call your storage function, passing the values returned from the form.
See the examples in the documentation links provided above.
If your web app used Html Services, you would have several options for calling server-side apps-script, see Html Service: Communicate with Server Functions. There are also numerous questions here that demonstrate this:
Call a Google Apps Script function in HTML
HtmlService form submit opens new tab with foo bar URL
Short answer:
google.script.run.nameOfYourFunction();
Use this to call your function that is defined outside of the html file, from within the html file. Based on the docs
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