0
在谷歌片腳本,我試圖從一個小區在手冊A複製值到另一個小區在片材B.GoogleSheet腳本細胞值設定
存在的問題是,當我開始avgUtilisationPerWeek()在谷歌功能工作表腳本編輯器,代碼正在完成這項工作,它將定義單元格的值。
但是當我使用formula = avgUtilisationPerWeek()從目標工作表調用函數時,它會報告#ERROR「您沒有權限調用setValue(第108行)」。
在自定義函數中,我試圖設置工作表中其他單元格的值,而不僅僅是放置公式的單元格。
這是源代碼:
function avgUtilisationPerWeek(){
for(var i = 1; i < 14; i++) {
Utilities.sleep(3000);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dynamic Weekly Utilisation Report').getRange('D1').setValue(i);
t1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dynamic Weekly Utilisation Report').getRange('L4').getValue();
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Graph Q1 2017').getRange((String.fromCharCode('A'.charCodeAt(0) + i)).concat('24')).setValue(t1);
v = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dynamic Weekly Utilisation Report').getRange('L5').getValue();
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Graph Q1 2017').getRange((String.fromCharCode('A'.charCodeAt(0) + i)).concat('29')).setValue(v);
g = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dynamic Weekly Utilisation Report').getRange('L6').getValue();
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Graph Q1 2017').getRange((String.fromCharCode('A'.charCodeAt(0) + i)).concat('34')).setValue(g);
t2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Dynamic Weekly Utilisation Report').getRange('L7').getValue();
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Graph Q1 2017').getRange((String.fromCharCode('A'.charCodeAt(0) + i)).concat('39')).setValue(t2);
}
}
我看了這個文章,但沒有找到解決方案。
Google Script setValue permission
Transferring cell data in Google Script?
如果我把的OnOpen功能的代碼腳本編輯器,並與=的OnOpen(),我收到消息「無法從該上下文調用用SpreadsheetApp.getUi()運行工作表中的功能。(線16)。」 –
你應該可以從菜單中運行它 - onOpen()在UI的其餘部分旁邊創建一個菜單。 – David