husayt
husayt

Reputation: 15159

How get appscript into new Google document

In our solution we open google docs editor for our users with some text to edit. They need certain functionality contained in the apps-script we have created. But we can't get that script into document automatically.

Some people suggested creating a document with the script and then copy it to new documents.

It is not possible unless you add the script to each document manually. For documents that are created henceforth, you can have a template document (the template doc has the script) and make a copy of it instead of creating a new document.

But this is not possible with public documents. Each user has to copy first document manually.

So is it possible to inject this script into that google docs document automatically?

Upvotes: 1

Views: 202

Answers (1)

rickcnagy
rickcnagy

Reputation: 1824

Google Docs Templates should work quite nicely for this. They will prefill with both editable text and whatever scripts you wish to be associated with the document. Just hit the Submit a template button in the upper right corner of the page and select the document you're looking to share.

EDIT to answer question from comments:

Believe it or not, the script will be installed along with the document! If you need the script to run the first time the user opens the sheet, use onInstall(). For an example of using the Drive Templates Gallery to install scripts that go along with Drive files (spreadsheet in this case), check out attendtime.com. In fact, Google actually recommends doing this in their documentation:

If your script depends upon a spreadsheet being formatted in a particular way or covers a very specific use case, then submitting a spreadsheet template that includes the script could be a better option. The Google Apps Script team has submitted some examples of spreadsheet templates that contain scripts.

They even have some examples of using the gallery for distributing scripts that go along with documents/spreadsheets here!

Upvotes: 1

Related Questions