java 脚本的新手。如何使用 App Scriptor 将我的 vba 自定义函数转换为在工作表中工作
New to java script. How to convert my vba custom function to work in sheets using app scriptor
我正在尝试根据我的 VBA 代码在 Google 工作表中创建我自己的自定义函数,但它不起作用。
Function MyRandBetween(lowint As Long, highint As Long) As Long
Randomize
MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0)
End Function
// Function MyRandBetween(lowint As Long, highint As Long) As Long
// Randomize
// MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0)
// End Function
const getRandom = (low, hi) => {
return Math.round(low + Math.random() * (hi - low));
};
console.log(getRandom(1, 10));
console.log(getRandom(30, 100));
console.log(getRandom(20, 30));
您只需使用 Math.random()。
Google 工作表中的示例:
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(MyRandBetween(1,100));
}
function MyRandBetween(low, high) {
return Math.floor(Math.random() * high) + low;
}
脚本:
结果:
我正在尝试根据我的 VBA 代码在 Google 工作表中创建我自己的自定义函数,但它不起作用。
Function MyRandBetween(lowint As Long, highint As Long) As Long
Randomize
MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0)
End Function
// Function MyRandBetween(lowint As Long, highint As Long) As Long
// Randomize
// MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0)
// End Function
const getRandom = (low, hi) => {
return Math.round(low + Math.random() * (hi - low));
};
console.log(getRandom(1, 10));
console.log(getRandom(30, 100));
console.log(getRandom(20, 30));
您只需使用 Math.random()。
Google 工作表中的示例:
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
SpreadsheetApp.getActiveSheet().getRange('A1').setValue(MyRandBetween(1,100));
}
function MyRandBetween(low, high) {
return Math.floor(Math.random() * high) + low;
}
脚本:
结果: