問題:當我運行該腳本,谷歌告訴我,「您沒有權限調用openById」GAS「您沒有權限調用openById」
我抄襲了一個腳本從另一個Google電子表格中更改變量的單元格引用,並在源表格和目標電子表格中創建了正確大小的命名範圍。
GAS文件沒有提到的原因,可能無法正常工作:
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openById%28String%29
另一種氣體文件說,它應該爲我工作,因爲我調用它從一個自定義菜單:
https://developers.google.com/apps-script/guides/sheets/functions#using_apps_script_services
上面的第二個鏈接說:
如果您的自定義函數引發錯誤消息您沒有 權限來調用X服務。,該服務需要用戶授權 ,因此不能用於自定義功能。
若要使用上述以外的服務,請創建一個自定義菜單 ,該菜單運行Apps腳本功能,而不是編寫自定義的 函數。如果需要,從菜單觸發的功能將要求用戶 授權,因此可以使用所有應用程序 腳本服務。
我試着把這個函數放到一個「自定義函數」項目中,然後放到一個「附加」項目中,但仍然得到了同樣的錯誤信息。
什麼我做錯了,如何使這項工作任何想法?
這裏是我的確切代碼:
function exportData_SStoSS() {
// Get the source data.
var source_ss = SpreadsheetApp.getActiveSpreadsheet();
var data = source_ss.getRangeByName("exportData").getValues();
// Identify the target.
var controls_sh = source_ss.getSheetByName("Controls");
var target_ssKey = controls_sh.getRange('C2').getValue();
var target_ss = SpreadsheetApp.openById(target_ssKey);
// Paste the data to the target.
target_ss.getRangeByName("importData").setValues(data);
};
是否有這些信息的官方消息來源? –