Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Script: How automatically open a created text document after have create it [duplicate]

I've used this script to create a Google text document (like word document) with Google Spreadsheet. But, when I do so, the new text document created from a template is placed in the default choosen folder. And, after that, I have to go to that folder, find the new document and open it. The million dollars question is: how could I make the knew created text document automatically open? (I think that if it wasn't a Google text Document but a spreadsheet I should use 'SpreadsheetApp.getActive()').

Thanks for any help and no, there are no million bucks.

like image 948
craftApprentice Avatar asked Dec 06 '25 05:12

craftApprentice


1 Answers

There is no way to automatically open a document, neither a spreadsheet without having the user do something to open it (at least click a link).

What you could do is to show a popup in your spreadsheet with a link that would open that document.

This is quite simple to do from a spreadsheet script, please refer to this post and to the docslist documentation.(use doc ID to access docsList.getUrl()


EDIT : following your comment, here is a possible way to automatically hide the popup, I included this in a full demo code.

function test(){
  var id = "1cZCL7T-enU0yJZnCb0WM0NeqXDHjnnBUyvs98vsyzwU";// test document (shared in view only)
  var Doc = DocsList.getFileById(id);
  showURL('Open document named "'+Doc.getName()+'"',Doc.getUrl());
}

function showURL(nameToShow,href){
  var app = UiApp.createApplication().setHeight(50).setWidth(300);
  app.setTitle("Show URL");
  var link = app.createAnchor(nameToShow, href);
  app.add(link);  
  var handler = app.createServerHandler('hide');
  link.addClickHandler(handler);// add serverHandler to the link itself
  var doc = SpreadsheetApp.getActive();
  doc.show(app);
}

function hide(){
  var app = UiApp.getActiveApplication().close();// close the popup window
  return app;// apply change
}
like image 54
Serge insas Avatar answered Dec 07 '25 17:12

Serge insas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!