The Interface and documentation for the Google Apps script is not very good there is lot of things and I'm not able to find anything useful in google search. I've created my own cloud project and my own google script project connected them using my permission screen and project. I've created code that works I've created trigger open but I have no idea what to do next how to add it to my document, so I can actually use my script on the document instead of the editor.
I need to create script that will be used by everyone that open my document in my organization.
My code looks like this:
function toggleBorders() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var tables = body.getTables();
var black = '#000000';
var white = '#ffffff';
tables.forEach(function(table) {
var color = table.getBorderColor();
table.setBorderColor(color == black ? white : black);
})
}
function onOpen() {
var ui = DocumentApp.getUi();
var menu = ui.createMenu('JJ Scripts').addItem('Toogle Borders', 'toggleBorders');
menu.addToUi();
}
I've not even able to run onOpen from editor because got error:
Cannot call DocumentApp.getUi() from this context
Is there a way to install Google App Script into my own document so I can actually use it outside of editor?
DocumentApp.getUi()
is only available for bound scriptsTools -> Script Editor
, pasting adn saving the codeonOpen()
once manually to give the script the necessary permissionsDocumentApp.getUi()
will fail, you need to use SpreadsheetApp.getUi()
instead (and rewrite toggleBorders()
)