Creating Google Doc from Google Spreadsheet - google-apps-script

I am creating an approval application using Google Spreadsheets and Mail app. At the end of the process, I think it would be a nice touch to end with a Google Doc, instead of just a Google Spreadsheet that is not appealing to the recipients. Is this possible?

Yes, it is possible.
You could use the Spreadsheet Service to extract the information using getRange() to then create a Google Doc from the Document Services. If you have a template Google Doc that you want to use, you could the File Make Copy (then using Document's replace text) to insert the necessary information.
Cheers.

It sounds like you want to do a mail merge. Check it the Autocrat script in the script gallery.

Related

Can I link a script to a google sheets which already has a script?

I have a google sheets which is linked to a form and a google scripts that was created in the menu of google sheets. This script runs fine and I use it to format the data. However, I have another script which I created from the google developer console, which sends and receives data from a website. I need this second script to get the value of a cell in the google sheets.
How can I link this second form to the google sheets while keeping the script already linked to the sheets?
When looking at responses to other questions they seem to be about individual sheets in a set so just to clarify, when referring to google sheets I mean the whole google sheets document. I only have one sheet anyways.
If it helps: The script I want to add acts a bit like a server and is being deployed by google scripts while the script that is already linked is only run when I call it on the sheets.
There is not way of attaching a standalone script to a document making it a bound script (which is the actual terminology for the script linked the the document).
The simplest way would be to copy-paste the code to the other script. You can deploy the bounded script.
If you really need more than one project for whatever reason, you can enable the Apps Script API and use projects.create (read reference) to create another one. If you don't know what this means, you probably shouldn't use it as it's finicky at best.
I found a solution which was to link the script to the google sheets using
var ss = SpreadsheetApp.openById("SHEET_ID_HERE");
I can then use ss.getActiveSheet().getRange().getValue();
and other funtions.
Thanks for the help!

Google Apps Script : Download PDF responses from Google Forms

I have created a Google form with few responses. I want to download those responses as PDF format into my local pc using a script run by Apps Script. I can't find any apis in Apps Script to do so.
Any ideas? Thank you.
When you have a Form, it will save your responses in a Sheet, as described here. You can export that sheet as PDF following step 2 in this tutorial using the UI.
If you want to use GAS, you can follow this tutorial, to show you how to create an add-on for it. You can also follow this answer to get a single sheet as a PDF.
However, I believe the suggestion of doing it with the UI will work best for you, since each form has only that Spreadsheet associated to it, and it will have only one sheet.

Is it possible to hide Google script from google sheet?

I have a Rest API available which I would like to make available via an Google sheet for less tech oriented people. I was wondering if it is possible to hide the google script from the sheet if I share it with people? I have some sensitive information in the code like the authentication etc which I would like to hide. Moreover, it would be nice if they can't infer with the code. Is this possible?
The only secure way is to create an add-on.
Related
How to protect the Apps Script code in a Google spreadsheet?

How to separate script editor from document (google apps script)

I'm writing some script for my Documents, Spreadsheets and Gmail. I would like to know if there is a way to save all my script to separate files in a specific google drive folder. I don't like having to go to the backend of my Documents and Spreadsheets in order to edit my script.
Would I have to call the document from my script using "getByID" or is there another way?
Yes, when you create a new document in Drive you can select Script. If you don't see the script option, try going here.
You will, however, need to call your document using getByID. There my be other complexities if you are using onEdit type triggers.
A lot more information can be found under the Types of Scripts heading at Google Apps Scripts Documentation.
You could go advanced and pull your script in behind the Document as a Library and then using the script behind the Doc to make the calls to the library, but that's a bigger discussion.

How can I add a Google apps script to a spreadsheet created using the API?

After reading up a lot on the Google Spreadsheet API I have come to the conclusion that formatting (such as merging cells, changing fonts etc) is only available throught the Apps scripts.
Since we need to create and fill the spreadsheets with data programatically using Java on the back-end I guess I need to somehow either;
link the new sheet to a Apps script that trigger on-load or
create a Apps script that creates the spreadsheet for me.
Anyone knows?
If you want to just "create" the spreadsheet, you don't need a script to load whenever it spreadsheet is opened. It's probably easier to develop a script that runs once and create the spreadsheet for you.
Another tip is to have a template file that you can copy with most of the formatting (if not all) already there. Possibly pending just little things that are related to the real data the new spreadsheet will have.
Edit to answer the question in the title.
No, you can not add a script to an existing spreadsheet programatically, only manually. What you can do is previously set up a template spreadsheet with a script in it and create new spreadsheets by copying this template.
(answering the comment)
You can run a script programatically, but not upload it. To run a script you can deploy it as a web-app and call its url with either a http get or post (will call its doGet or doPost functions, that you must have declared). Also, you could set this script to run on form submit of any spreadsheet-form and just submit a set of answers to this form. At last (that I can think of now) you could just add the script as a library in another Apps Script and call it directly.
(Aug 2016) There is no way programmatic way to link a Google Sheet and Apps Script code other than manually. Based on what it seems you want ("create and fill the spreadsheets with data programatically using Java"), you can now do it without Apps Script.
TL;DR: Above, #Henrique has answered multiple questions and even questions that weren't asked! The good news is that today, we have more answers representing alternate possible solutions to what you're seeking.
It's now possible to "upload" Apps Script code programmatically with the
import/export system, say with Eclipse since you're a Java developer (2013 announcement).
I agree with Henrique's suggestion that if you create a spreadsheet
template, i.e., Excel file, you can use the Google Drive API to
programmatically import/create identical Google Sheets with all your
desired formatting.
"Formatting (such as merging cells, changing
fonts etc)" can now be done outside of Apps Script, as there is a
"new" Google Sheets API v4 (not GData).
In order to use the new API, you need to get the Google APIs Client Library for Java and use the latest Sheets API, which is much more powerful and flexible than any previous API. Here's one code sample to help get you started. If you're not "allergic" to Python, I also made a video with a different, slightly longer example introducing the new API and gave a deeper dive into its code via a blogpost that you can learn from.
Note the v4 API allows you to create spreadsheets & sheets, upload & download data, as well as, in the general sense, programmatically access a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.), but to perform file-level access such as uploads & downloads, imports & exports (same as uploads & downloads but conversion to/from Google Apps formats), you would use the Drive API instead.