Home > Software engineering >  How add action button to google-doc?
How add action button to google-doc?

Time:05-11

I want to add button or another widget with click action to my Google Document with Apps Scripts; How will i can do it?

function addButton()
{
  var body = DocumentApp.getActiveDocument().getBody();
  // code for add button to body.
}

CodePudding user response:

Create a menu

function onOpen() {
   menu();
}

function menu() {
  DocumentApp.getUi().createMenu('MyMenu')
  .addItem('Function Descript', 'functionName')
  .addToUi();  
}

function functionName() {
  //a function that does nothing
}

Your best bet is to learn how to do this on your own so that you don't have to return here everytime you require a modification.

If you wish to add buttons I would recommend placing them on a sidebar with html. That will take a little more effort but in the long run it will be worth learning how to build and reuse the html file.

Reference:

  • Related