问题
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