wps怎么用js宏实现查找(JS宏中的应用场景)
wps怎么用js宏实现查找(JS宏中的应用场景)
在ES6标准中引入了rest参数(形式为…变量名),用于获取函数的不固定参数。rest参数搭配的变量是一个数组,该变量将多余的参数放入数组中。rest参数之后不能再有其他参数,否则会报错。
变长参数,指的是函数参数数量可变,或者说函数接受参数的数量不固定。
testduo: Function(canshu1 ...canshu2)
{
console.log(canshu1);
console.log("------------------------------")
for(var canshu of canshu2)
{
console.log(canshu)
}
}
this.testduo("参数1" "参数2" "参数3" "参数4" "参数5" "参数6");
function CustomerFunc(rngs ...operation)
{
var wsf=WorksheetFunction
var result="";
var currentResult="";
for(var opr of operation)
{
switch(opr)
{
case "sum":
currentResult="合计:" wsf.sum(rngs)
break
case "average":
currentResult="平均:" wsf.average(rngs)
break
case "max":
currentResult="最大:" wsf.Max(rngs)
break
case "min":
currentResult="最小:" wsf.Min(rngs)
break
default:
currentResult="未定义该操作"
break
}
result=result "\n" currentResult
}
return result.slice(1)
}
function test()
{
var range=Range("A1:A9")
Range("C2").Value2=CustomerFunc(range "sum" "average" "big")
}
//1.计算参数和
function sumAll(...Args) {
let sum = 0;
for (let arg of args) sum = arg;
return sum;
}
console.log( sumAll(1) );
console.log( sumAll(1 2 3) );
//2.每个参数乘以2
function multiply(multiplier ...theArgs) {
return theArgs.map(function(element) {
return multiplier * element;
});
}
var arr = multiply(2 1 2 3);
console.log(arr);
//3.排序
function sortRestArgs(...theArgs) {
var sortedArgs = theArgs.sort();
return sortedArgs;
}
console.log(sortRestArgs(5 3 7 1));
示例图