當我將 toast 添加到函式并運行或除錯該函式時,toast 不顯示,日志中沒有錯誤,并且在控制臺中顯示之前或之后的任何記錄訊息。但是,當我將完全相同的 toast 代碼放在空白電子表格的應用程式腳本中時,toast 會顯示。
SpreadsheetApp.getActiveSpreadsheet().toast('Script is starting');
SpreadsheetApp.getActiveSpreadsheet().toast('? Script running', 'Notice', 60);
我確實在 appsscript.json 檔案的 Oauth 范圍中添加了檔案中的兩個范圍:
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
還有其他原因導致表格中無法顯示吐司嗎?謝謝!
uj5u.com熱心網友回復:
為了使 Google 表格 UI 方法toast正常作業,
- 該腳本應系結到電子表格,或者它應該是一個編輯器插件
- 如果腳本將從 Google Apps 腳本編輯器運行,則應通過 Google 表格用戶界面打開它:
- 打開電子表格
- 單擊擴展程式 > Apps 腳本
為了更容易除錯代碼,您可能會發現將活動電子表格分配給變數更方便:
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
if(spreadsheet) {
spreadsheet.toast('Script is starting');
} else {
throw new Error(`Can't get the active spreadsheet`);
}
注意:登錄多個帳戶可能會導致腳本無法正常運行。嘗試退出所有帳戶,并僅登錄有權訪問電子表格的帳戶或與您的其他帳戶共享電子表格。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/473305.html
