gpt4 book ai didi

Javascript 代码放置

转载 作者:行者123 更新时间:2023-11-30 06:06:20 25 4
gpt4 key购买 nike

这是我用于 google 电子表格的脚本。除了最后两行代码外,一切正常。我不确定在哪里让他们工作。我知道他们是正确的,我猜只是不在正确的位置?

 function doStuff() {
var ss = SpreadsheetApp.getActiveSheet();

var starting_row = 2; // starting row to scan for part# on column C

// outer loop, loop over products sold
for (var j=6;j<=16;j++) {
var r = ss.getRange(j,2);
// read inventory part number entered
var partnum = r.getValue();
if (!partnum) {
continue; // attempt to skip over empty rows in the B6:B16 range
}
var partcount = parseInt(ss.getRange(j,1).getValue());
if (isNaN(partcount) || partcount<=0) {
// invalid quantity. skip.
continue;
}

// Browser.msgBox("partnum = "+partnum);

// get list of known part # from the spreadsheet
var parts = ss.getRange(starting_row,3,9999,1).getValues();
var found = false;
for (var i=0,l=parts.length;i<l;++i) {
if (parts[i]==partnum) {
// we have found our part. grab inventory count cell.
found = true;
var count = ss.getRange(starting_row+i,1).getValue();
if (count-partcount<0) {
Browser.msgBox("Error: Inventory for part "+partnum+", is "+count);
} else {
// write back the count number for that part, decremented by 1.
ss.getRange(starting_row+i,1).setValue(count-partcount);
// Browser.msgBox("Inventory updated.");
}
break; // either way, we're done with that part.
}
}
if (!found) {
Browser.msgBox("Part# "+partnum+" not found.");

**//I'm not sure where to place these next two lines. Everything else works but them. The code is correct just not the placement.
SpreadsheetApp.getActiveSpreadsheet().toast("Hello", "world?", 3);
SpreadsheetApp.getActiveSheet().getRange(6, 1, 10, 1).clear({contentsOnly:true});**
}
}

}

最佳答案

他们应该在那个 if block 中吗?可以尝试将它们放在最后一个 }

的正上方

我不熟悉谷歌电子表格,所以这完全是我的猜测。在那个 if block 中似乎不合适......

来自这里:

        if (!found) {
Browser.msgBox("Part# " + partnum + " not found.");
SpreadsheetApp.getActiveSpreadsheet().toast("Hello", "world?", 3);
SpreadsheetApp.getActiveSheet().getRange(6, 1, 10, 1).clear({
contentsOnly: true
});
}
}

}

也许是这样的:

        if (!found) {
Browser.msgBox("Part# " + partnum + " not found.");

}
}
SpreadsheetApp.getActiveSpreadsheet().toast("Hello", "world?", 3);
SpreadsheetApp.getActiveSheet().getRange(6, 1, 10, 1).clear({
contentsOnly: true
});
}

关于Javascript 代码放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4370918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com