Edit google document remotely
I am trying to add a function to my site like this:
Clicking the button adds text to the Google document.
Obviously I will need to create a Script application on disk. The question is how to run Script applications from my site. It can be assumed that I am the owner of the disc / document and therefore have the rights to edit it in any way.
I covered the following topics:
- Workarounds: how to edit google source documents as a doc? item
- How to programmatically manipulate native files google docs
It seems that all the actions are done from the disk itself and are not started remotely.
I've also searched for the Script Apps API on Google but couldn't find a way to do this. Is it possible?
source to share
Yes it is possible.
First, write an Applications script that will modify your desired document. Then deploy it as a web application working like you , who has access, even anonymous. Check out the tutorials on the Applications page script to learn how to write a script as a web application.
After that, your script will have a public url that you can call on your website and run it "remotely".
source to share
To provide an example of what Enrique suggests, here's a small webapp that adds text to the public document I own (it shouldn't be publicly available, except those here to check if it works!)
I wrote it with UiApp, but you can of course use HTMLService if you like ...
The application works like me, but is available to anyone anonymous.
// publicly viewable test doc url : https://docs.google.com/document/d/1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM/edit
function doGet(){
var app = UiApp.createApplication().setTitle('docEdit');
var panel = app.createAbsolutePanel().setSize('100%','100%').setStyleAttributes({'padding':'40px','backgroundColor':'lightBlue'});
var text = app.createTextArea().setName('text').setPixelSize(500,300);
var grid = app.createFlexTable().setId('grid');
grid.setText(0,0,'Add your text').setWidget(1,0,text);
var handler = app.createServerHandler('writeText').addCallbackElement(panel);
grid.setWidget(2,0,app.createButton('update document',handler).setId('btn'));
app.add(panel.add(grid));
return app;
}
function writeText(e){
var doc = DocumentApp.openById('1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM');
var now = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM/dd/yyyy @ hh:mm:ss');
var body = doc.getBody();
body.appendParagraph('Append text on '+now+' : '+e.parameter.text);
doc.saveAndClose();
var app = UiApp.getActiveApplication();
var grid = app.getElementById('grid');
grid.setWidget(3,0,app.createHTML('Thanks,<br>Your text has been added to the document'));
app.getElementById('btn').setEnabled(false).setHTML('Button disabled');
return app;
}
source to share