[問題] google script 如何執行

作者: seft584f8 (seft584f8)   2023-03-03 15:47:46
最近嘗試寫google script(中文被翻成錄製巨集,奇怪的翻譯..
但應該實際上是script editor )
寫了一段code,
目標是針對一個cell作為一個按鈕, click該按鈕其對應的cell的數值減1
function myFun_onclick123123321321() {
// Step 1: Get the position of the current cell (row, col)
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRow();
var col = cell.getColumn();
// Step 2: Use VLOOKUP to get the value of the target cell in 料件表
var table2Sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("料件
表");
var lookupRange = table2Sheet.getRange("A:M");
var lookupValue = sheet.getRange(row + 4, col).getValue();
var columnIndex = 6; // You may need to adjust this depending on which
column you want to look up
var targetCell = SpreadsheetApp.functions.vlookup(lookupValue, lookupRange,
columnIndex, false);
// Step 3: If the value of the target cell in table2 is greater than 0,
decrement it by 1
if (targetCell.getValue() > 0) {
targetCell.setValue(targetCell.getValue() - 1);
}
}
我點執行嘗試看看是否有bug時,
出現一個視窗: 需要授權
我選審查驗證之後需要重新登入google帳號
登入後出現以下文字:
系統已封鎖這個應用程式
這個應用程式嘗試存取您 Google 帳戶中的機密資訊。為保護您的帳戶,Google 已阻擋
這個存取行為。
( 我把code簡短到什麼都沒寫也會出現此訊息, 所以估計應該跟程式沒關係, 而是可能
需要某種權限 或者要升級商業模式? )
請問大大知道怎麼讓google scrip寫好後可以使用嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com