Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 310
Magnus Avatar asked Nov 04 '12 13:11

Magnus


1 Answers

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.

like image 155
Henrique G. Abreu Avatar answered Sep 19 '22 13:09

Henrique G. Abreu