[问题] 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