Can scripts write/read directly to/from Google Document? - javascript

I want to create a script that would do the followings:
create a form
once a user fill the form and submit, the script would copy a
previously created Google Document "template" and fill out the fields
the copied template with the information submitted.
Now I am aware that you can not create scripts within the "Document" container (only Spreadsheet and Sites), but can a standalone Google Apps Script read or write directly to Document like the way it could with Spreadsheet?
I read somewhere that Google Apps Script can not read text from a Google Document, but only text and CSV. Is that still true with the recently update to Google Apps Script?

Yes, this can be done. The easiest example to follow is Employee of the Week example. This takes in user input , merges it into a doc and automatically emails the result out to the user, which you can remove if you like. There also a video tutorial. Should get you pointed in the right direction.

Yes, you can use DocumentApp.

Related

is there a way to retrieve information from a webpage and use that info to prefill another page?

I'd like to create a browser extension or a javascript to retrieve pieces of information from a currently open webpage and use that info to prefill a form on another webpage.
So, for example, if I'm on a StackOverflow page, I'd like a script that takes info from that page (title, question,...) and prefill that data in a new webpage (eg: https://stackoverflow.com/questions/ask).
I'm not an expert in coding, but I created some scripts using Python and Selenium (nothing too fancy though). I looked for a similar question, but I didn't find anything. Does anyone have an idea on how I could accomplish something like that?
You can do it with the help of content script. fetch the required data from any webpage using a content script and store the data on extension storage. Then you can inject the data to required input on required webpage with executeScript()
for more reference: https://developer.chrome.com/extensions/content_scripts

How to show a notification if a word is present anywhere on an URL, even in pop-up

Please excuse if this is a silly question. I was trying to create a chrome extension which will read the text in a web page and notify a user by any means if it is present at page anywhere even in pop up.
I have created extension but not getting how to write logic.
If any specific word is present then that should be flagged by any means. Those specific words can be maintained in a Google sheet and extension can use that as a reference to flag.
I agree with #wOxxOm, go through the official tutorial to get a good understanding of what you're trying to accomplish and how to use the content script.
And IMO, I would use Chrome.storage api chrome storage api, if they're saved to a variable, you can then access it locally, instead of you checking google sheets or some other external site, you're just checking the stored object.

Use Google Apps Script to fill out a PDF form saved on my Google Drive

I have this built in Excel, but struggling to transition it to Google Sheets. I have customer information in a Sheet (name, address, services...) and a PDF which needs to be filled from this information. I saw suggestions to use DocHub, but that doesn't seem to get me there, and I need the rest of the formatting and data in the PDF, not just outputting or printing the sheet as a PDF.
So: PDF is in my Google Drive. It has editable fields. I want to fill those fields with specified data from my Google Sheet.
I'm OK with it being a script that I modify (I do a lot of scripting) or a MailMerge or an add-on or any other method.
Take a look at the PDFFiller API or something similar. Alternatively PDFFiller have a GSheets Add-on you can use to complete a PDF template.

display external text from txt, html etc. (hosted on cloud) on web page

I manage a small web page for a relative's business. They want to provide notes on the page for the visitors regularly (opening times, news etc.) but cannot code the web page themselves.
Is there a way to embed a news scroller, text field, whatever on the page - however, the text displayed there then comes from an external source they can manage like a htm, txt, json (whatever) file hosted e.g. on their Google Drive that they simply need to change and see the edits directly in the web page (the file would be public; the URL to be embedded in the web page code).
Is there a solution or an easier way to achieve it? thx
You can use file_get_contents() if I got you right.
To achieve this, first you need to create a portion on the website to display the news or whatever external dynamic content you want.
Then you need to develop complete APIs for that site and then hit them from your website (Keep a secret key for safety). Your API can do everything you program it to do. (E.g You can put the news in database or create publicly accessible files through it)
When this is achieved, you can then fetch the data into the portion created for news etc. (automated through programming)
Using PHP you can achieve all the above mentioned steps.
That way you will just have to push/send the data from your APIs and the actual site will keep getting updated without any further action required.
Hope that helps.
If they can write the HTML and make it available at a public URL, you can simply embed it using <iframe> in HTML.

Getting the javascript "document HTML DOM" info within Google Apps Script

I'm having a Google spreadsheet embedded in an (Episerver) page and the spreadsheet is editable. I also have a trigger onEdit in the sheet. When running that script 'onEdit' I'd like to get the info from current page using "document.getElementsByClassName().innerHTML" to get the context of the current situation, meaning fetching the username that is currently logged in that is displayed in the section within an element.
I'm getting the error 'document is not defined' and I got the reason. This is working just running the script as a pure javascript on the site. There is no success using GAS URLFetchApp since it not fetching the current page with the current user logged in. As I see it I have two possible options:
a) Is there anyway to use HTML DOM (document...) within Google Apps Script?
b) Can I fetch current page instead of fetching a new URL in Google Apps Script?
A) I think your only option here is to us the XML service.
B) I don't believe so, as the script is self contained, and doesn't have the ability to interact with the browser. You need to know a URL in order to fetch it.
However, you mention that part of what you'd like to do is fetch the user that is currently logged in, so perhaps you might be interested in the '.getActiveUser()' method? It might be a potential solution.

Categories