如何使用按钮(在客户端上)从现有电子表格中打开新电子表格? [英] How to open a new spreadsheet from an existing spreadsheet using a button (on Client Side)?

查看:164
本文介绍了如何使用按钮(在客户端上)从现有电子表格中打开新电子表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google电子表格中创建一个指向另一个电子表格的按钮. Spreadsheet.OpenbyUrl()在服务器端而不是客户端端打开电子表格.

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');
}

推荐答案

使用按钮,您只能调用服务器功能.服务器功能无法在浏览器中打开选项卡或窗口.

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

那是不行的.

但是您可以有一个按钮(或菜单项),该按钮将打开一个带有链接的对话框.该链接将打开URL(因为它是客户的代码).

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.

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>";

这篇关于如何使用按钮(在客户端上)从现有电子表格中打开新电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆