Google Apps Script : Download PDF responses from Google Forms - google-apps-script

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.

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!

On a Google Sheets, is there a way to trigger a Google Script function from a standalone webpage <button>?

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.

Importing editable HTML into Google Sheets

I know how to important HTML Data into Google Sheets so that it displays, but I am trying to figure out if it is possible to also copy a web data entry form into Google Sheets, so that you can enter values, which would then be presented by the data.
I am trying to import this calculator into Google Sheets so that I can work with the real time values.
http://www.coinwarz.com/calculators/ethereum-mining-calculator
Any ideas about how I can do this?
I am not aware of any way to import the actual HTML form into Google Sheets. However, here is how I would do it:
I would open Chrome and find the outgoing POST request that occurs when you press the green Calculate button on that site.
I would use Postman to test and create the request and see if it works.
Using Google Apps Script, you can issue HTTP requests. I would re-construct the request being sent in Google Apps Script.
To make it look nicer, you can re-construct the calculator in your Google Sheet. You can recreate the calculator's input buttons as cells and then fetch those cells in your GAS code (like, hash_rate_cell.getValue()):

Creating Google Doc from Google Spreadsheet

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.

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.