How to open a new spreadsheet from an existing spreadsheet using a button (on Client Side)?

不羁的心 提交于 2020-01-25 08:48:04

问题


I am trying to make a button in a Google spreadsheet which points to another spreadsheet. The Spreadsheet.OpenbyUrl() opens the spreadsheet on the Server side and not the client side.

Can anyone Help??

function open()
{  
 SpreadsheetApp.openByUrl('xxx');
}

回答1:


Using a button, you can only call a server function. And server functions can not open a tab or window in your browser.

That's a no go.

But you can have a button (or a menu item) that will open a dialog box with a link in it. That link will open the URL (because it's a client's code).

So it will be a two steps action.

Code:

function showLink(){
  var html = "<a href='https://docs.google.com/spreadsheets/d/1r-y7vidMXbPrxsg_tgL22eZcUqLNIBonJFB6k_iQb9c'; target='_blank'>Open this url</a>";
  var anchor = HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME).setHeight(60).setWidth(150);
  SpreadsheetApp.getUi().showModalDialog(anchor,"Click this link")
}

You can also close it automatically:

  var html = "<a href='https://docs.google.com/spreadsheets/d/1r-y7vidMXbPrxsg_tgL22eZcUqLNIBonJFB6k_iQb9c'; target='_blank'  onclick='google.script.host.close()' />Open this url</a>";


来源:https://stackoverflow.com/questions/31210489/how-to-open-a-new-spreadsheet-from-an-existing-spreadsheet-using-a-button-on-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!