[英]how to programmatically open a new spread sheet from google scripts
in setActiveSpreadSheet doc the example is very clear:在setActiveSpreadSheet文档中,示例非常清楚:
// The code below will make the spreadsheet with key "1234567890" the active spreadsheet
var ss = SpreadsheetApp.openById("1234567890");
SpreadsheetApp.setActiveSpreadsheet(ss);
however implementing that inside my google scripts, nothing happens at all (not even an error message).. ideas?但是在我的谷歌脚本中实现它,根本没有任何反应(甚至没有错误消息)......想法?
Based on the answers below, it's clear that the above code has no effect on UI.根据下面的答案,很明显上面的代码对 UI 没有影响。 I tried doing this:我尝试这样做:
function goToEstimate(sheetId)
{
window.open('https://docs.google.com/spreadsheets/d/'+sheetId);
}
but then I got this error:但后来我收到了这个错误:
ReferenceError: "window" is not defined.
Is there a way to access the javascript global window variable from within google scripts?有没有办法从谷歌脚本中访问 javascript 全局窗口变量?
An Apps Script cannot make a spreadsheet appear in a client's browser, since it is a server side script. Apps 脚本无法使电子表格出现在客户端的浏览器中,因为它是服务器端脚本。
The method openById
returns a handle on a spreadsheet which makes it possible to manipulate with the spreadsheet from the Apps Script.方法openById
返回电子表格的句柄,这使得可以从 Apps 脚本使用电子表格进行操作。 This is what "to open a spreadsheet" means for a script.这就是“打开电子表格”对于脚本的意义。 This action has no effect on user's interface.此操作对用户界面没有影响。
The method setActiveSpreadsheet
is pretty much useless;方法setActiveSpreadsheet
几乎没用; it only changes which spreadsheet will be returned when a script calls getActiveSpreadsheet
.它只会更改脚本调用getActiveSpreadsheet
时将返回的电子表格。
One method that does have effect on UI is setActiveSheet
: if it is applied to a spreadsheet that a user has opened in their browser, the method can change which tab/sheet of that spreadsheet is facing the user.对 UI 有影响的一种方法是setActiveSheet
:如果将其应用于用户在浏览器中打开的电子表格,则该方法可以更改该电子表格的哪个选项卡/工作表面向用户。
I guess, you can't just open new tab in browser and open new spreadsheet by script.我想,您不能只是在浏览器中打开新标签页并通过脚本打开新电子表格。 That's because script can't control browsers.那是因为脚本无法控制浏览器。 But you could get data from closed Spreadsheet:但是您可以从关闭的电子表格中获取数据:
function openSheetTest() {
var newWs = SpreadsheetApp.openById('1234567890');
var sheet = newWs.getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
Logger.log(data);
}
There's is a class Browser in G-sheets. G-sheets 中有一个类浏览器。 And all we can for now is to make promts or MsgBoxes.我们现在所能做的就是制作提示或 MsgBoxes。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.