![](/img/trans.png)
[英]How to set dynamically value from a google spread sheet to another google spread sheet cell
[英]how to programmatically open a new spread sheet from google scripts
在setActiveSpreadSheet文檔中,示例非常清楚:
// The code below will make the spreadsheet with key "1234567890" the active spreadsheet
var ss = SpreadsheetApp.openById("1234567890");
SpreadsheetApp.setActiveSpreadsheet(ss);
但是在我的谷歌腳本中實現它,根本沒有任何反應(甚至沒有錯誤消息)......想法?
根據下面的答案,很明顯上面的代碼對 UI 沒有影響。 我嘗試這樣做:
function goToEstimate(sheetId)
{
window.open('https://docs.google.com/spreadsheets/d/'+sheetId);
}
但后來我收到了這個錯誤:
ReferenceError: "window" is not defined.
有沒有辦法從谷歌腳本中訪問 javascript 全局窗口變量?
Apps 腳本無法使電子表格出現在客戶端的瀏覽器中,因為它是服務器端腳本。
方法openById
返回電子表格的句柄,這使得可以從 Apps 腳本使用電子表格進行操作。 這就是“打開電子表格”對於腳本的意義。 此操作對用戶界面沒有影響。
方法setActiveSpreadsheet
幾乎沒用; 它只會更改腳本調用getActiveSpreadsheet
時將返回的電子表格。
對 UI 有影響的一種方法是setActiveSheet
:如果將其應用於用戶在瀏覽器中打開的電子表格,則該方法可以更改該電子表格的哪個選項卡/工作表面向用戶。
我想,您不能只是在瀏覽器中打開新標簽頁並通過腳本打開新電子表格。 那是因為腳本無法控制瀏覽器。 但是您可以從關閉的電子表格中獲取數據:
function openSheetTest() {
var newWs = SpreadsheetApp.openById('1234567890');
var sheet = newWs.getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
Logger.log(data);
}
G-sheets 中有一個類瀏覽器。 我們現在所能做的就是制作提示或 MsgBoxes。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.