如何使用按钮在新标签页中打开电子表格? [英] How can i open a spreadsheet in a new tab with a button?
问题描述
我想在googlesheet/google Apps脚本中创建一个按钮,当您单击它时,该按钮会在新标签页中打开现有的google表格.我将按钮插入到Google工作表中,所以基本上我只需要一个链接到按钮的代码即可. 以下代码无法正常工作? 你能帮我吗?
I want to create a button in a googlesheet/google Apps Script that opens an existing google sheet in a new tab when u click on it. I will insert the button in a google sheet, so i basically just need a code that i link to the button. The code below does not work somehow? Can you help me?
function openURL(){
var button = CardService.newTextButton()
.setText("This button opens a link in an overlay window")
.setOpenLink(CardService.newOpenLink()
.setUrl("google sheet")
.setOpenAs(CardService.OpenAs.OVERLAY)
.setOnClose(CardService.OnClose.RELOAD_ADD_ON));
};
推荐答案
要创建此类按钮和功能,您将必须:
In order to create such button and functionality, you will have to:
-
创建单击后将执行的代码.转到工具">脚本编辑器".粘贴以下代码(当然,请替换相应的网址):
Create the code that will be executed upon clicking it. Go to Tools>Script Editor. Paste the following code (replacing, of course, the url for the appropriate one):
function openMySpreadsheet() {
var url = 'YOUR_SHEET_URL';
var htmlTemplate = HtmlService.createTemplateFromFile('js');
htmlTemplate.url = url;
SpreadsheetApp.getUi().showModalDialog(htmlTemplate.evaluate().setHeight(10).setWidth(100), 'Opening Sheet...');
}
仍然从Google Apps脚本IDE转到文件">新建">"HTML文件".将文件名设置为js
并将以下代码粘贴到其中:
Still from the Google Apps Script IDE, go to File>New>HTML File. Set the file name to be js
and paste the following code into it:
<script>
window.open('<?=url?>', '_blank', 'width=800, height=600');
google.script.host.close();
</script>
返回到表格"文档,并使用插入">图像">图像" 在单元格上插入图像,然后选择您想要的任何图像作为按钮.
Go back to your Sheets document and insert an image using Insert>Image>Image over cells and select any image you would like to have as your button.
从现在开始,每次单击该按钮时,都会显示一个短暂的对话框(这是打开新标签页上的链接所必需的),并且该链接将自动打开.
From now on, each time you click on the button, a short-lived dialog will be shown up (that is necessary in order to open a link on a new tab) and the link will be automatically open.
这篇关于如何使用按钮在新标签页中打开电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!