问题
This is related to a question I have posted previously.
I have a batch of CSV files that contain a data set obtained from an issue tracker tool. These I've uploaded to google drive and are presented as charts and lists from a google site.
This works reasonable well as all I now have to do is update the files in google drive and the site is automatically updated.
The displayed charts work well, but I want to present the lists as an HTML table (as opposed to an embedded sheet).
An app script seems the most logical way to do this. However, in order to do this, I need to provide the URL of the sheet containing the data to the app script. This is proving to be more difficult than I anticipated.
I attempted passing the data source as a parameter by directly linking the app script URL (xxxxxx/exec?source=yyyy), but the app script gadget in google sites doesn't pass through parameters.
I attempted to embed the script URL (with parameters) within an iframe - as suggested elsewhere, but without any luck.
Has anyone got any suggestions? Thanks.
回答1:
Google Apps Script gadget can't include parameters in the gadget settings, instead, add the parameters to the links to the Google Site page
https://sites.google.com/sites/mysite/mypage?par1=A&par2=B
Regarding having several instance of the same Google Apps Script gadget that could be a problem. I think that the better way to proceed is to make copies of your script and make a different set of parameters for each one.
Step by step
- Create a site
- Create a script
Add the gs code
In this case the code create a template from a file that has a printlet that shows the
Hellow World!
if the URL parametermessage
is equal totrue
, otherwise it you showundefined
.function doGet(e) { var template = HtmlService.createTemplateFromFile('Index'); if(e.parameter.message === 'true') template.message = 'Hello World!'; var output = template.evaluate(); return output; }
Create a HTML file and add the HTML code
<!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <p><strong>Message:</strong> <?!=message?></p> </body> </html>
Publish your web app
- Create a page
- Insert a Google Apps Script gadget
- Save the page
Write the page URL and the required parameters in the browser address box or in a link
https://sites.google.com/a/rubenrivera.mx/ejemplos/posts/1?message=true
来源:https://stackoverflow.com/questions/44490515/invoke-app-scripts-with-parameters-from-classic-google-site