rapid-spreadjs 1.0.66 → 1.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +92 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +92 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -19449,7 +19449,7 @@ const FormulaUtils = {
|
|
|
19449
19449
|
optional: false,
|
|
19450
19450
|
},
|
|
19451
19451
|
{
|
|
19452
|
-
name: '
|
|
19452
|
+
name: '比较大小或比较相等的字符串,格式为:“>”、“<”、“>=”、“<=”、“=”、“±”',
|
|
19453
19453
|
repeatable: false,
|
|
19454
19454
|
optional: false,
|
|
19455
19455
|
},
|
|
@@ -19463,68 +19463,141 @@ const FormulaUtils = {
|
|
|
19463
19463
|
repeatable: false,
|
|
19464
19464
|
optional: false,
|
|
19465
19465
|
},
|
|
19466
|
+
{
|
|
19467
|
+
name: '是否返回相反的结果(传数字的1或0,0:满足条件的结果、1:相反的结果),默认为:0',
|
|
19468
|
+
repeatable: false,
|
|
19469
|
+
optional: false,
|
|
19470
|
+
},
|
|
19466
19471
|
],
|
|
19467
19472
|
funCallback: (spread, sheet, retData) => {
|
|
19468
|
-
//如果传递的参数小于
|
|
19469
|
-
if (retData.allCellValsEw.length <
|
|
19473
|
+
//如果传递的参数小于6个,则返回空字符串
|
|
19474
|
+
if (retData.allCellValsEw.length < 6) {
|
|
19470
19475
|
return '';
|
|
19471
19476
|
}
|
|
19472
|
-
|
|
19477
|
+
let array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4], isOpposite = retData.allCellValsEw[5];
|
|
19473
19478
|
try {
|
|
19479
|
+
// 处理array1和array2的默认值
|
|
19480
|
+
if (array1 == null || array1 == undefined || (typeof array1 == 'string' && array1.trim().length == 0)) {
|
|
19481
|
+
array1 = [];
|
|
19482
|
+
}
|
|
19483
|
+
if (array2 == null || array2 == undefined || (typeof array2 == 'string' && array2.trim().length == 0)) {
|
|
19484
|
+
array2 = [];
|
|
19485
|
+
}
|
|
19486
|
+
if (typeof array1 == 'string' && array1.trim().length > 0) {
|
|
19487
|
+
array1 = [array1];
|
|
19488
|
+
}
|
|
19489
|
+
if (typeof array2 == 'string' && array2.trim().length > 0) {
|
|
19490
|
+
array2 = [array2];
|
|
19491
|
+
}
|
|
19492
|
+
// 如果operator、value、delimiter、isOpposite为数组,则设置其取第一个值
|
|
19493
|
+
if (Array.isArray(operator) && operator.length > 0) {
|
|
19494
|
+
operator = operator[0];
|
|
19495
|
+
}
|
|
19496
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
19497
|
+
value = value[0];
|
|
19498
|
+
}
|
|
19499
|
+
if (Array.isArray(delimiter) && delimiter.length > 0) {
|
|
19500
|
+
delimiter = delimiter[0];
|
|
19501
|
+
}
|
|
19502
|
+
if (Array.isArray(isOpposite) && isOpposite.length > 0) {
|
|
19503
|
+
isOpposite = isOpposite[0];
|
|
19504
|
+
}
|
|
19505
|
+
// 设置isOpposite的默认值
|
|
19506
|
+
if (isOpposite == '1' || isOpposite == '0') {
|
|
19507
|
+
isOpposite = parseInt(isOpposite);
|
|
19508
|
+
}
|
|
19509
|
+
if (isOpposite != 0 && isOpposite != 1) {
|
|
19510
|
+
isOpposite = 0;
|
|
19511
|
+
}
|
|
19512
|
+
// TODO:暂定此情况
|
|
19513
|
+
// 第一个参数是否为单值(array1为一个值的时候,此时array2的所有元素可能需要参与计算,满足要求的就返回array2中的值)
|
|
19514
|
+
const isSingleValue1 = array2.length > array1.length && array1.length == 1;
|
|
19474
19515
|
// 参数基础校验
|
|
19475
19516
|
if (!Array.isArray(array1) ||
|
|
19476
19517
|
!Array.isArray(array2) ||
|
|
19477
|
-
array1.length !== array2.length ||
|
|
19518
|
+
// array1.length !== array2.length ||
|
|
19478
19519
|
typeof operator !== 'string' ||
|
|
19479
19520
|
typeof delimiter !== 'string') {
|
|
19480
19521
|
return '/';
|
|
19481
19522
|
}
|
|
19482
19523
|
// 验证operator参数的有效性
|
|
19483
|
-
const validOperators = ['>', '<', '>=', '<=', '='];
|
|
19524
|
+
const validOperators = ['>', '<', '>=', '<=', '=', '±'];
|
|
19484
19525
|
if (!validOperators.includes(operator)) {
|
|
19485
19526
|
return '/';
|
|
19486
19527
|
}
|
|
19487
19528
|
// 判断第一个数组的元素类型
|
|
19488
19529
|
const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
|
|
19489
|
-
//
|
|
19490
|
-
const validIndices = [];
|
|
19491
|
-
for (let i = 0; i <
|
|
19530
|
+
// 收集满足条件的索引和不满足条件的索引
|
|
19531
|
+
const validIndices = [], oppositeIndices = [];
|
|
19532
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19492
19533
|
let conditionMet = false;
|
|
19493
19534
|
if (isNumericArray) {
|
|
19494
|
-
//
|
|
19495
|
-
const num1 = parseFloat(array1[i]);
|
|
19535
|
+
// 第一个参数为单值的时候,取第一个值
|
|
19536
|
+
const num1 = isSingleValue1 ? parseFloat(array1[0]) : parseFloat(array1[i]);
|
|
19537
|
+
const num2 = parseFloat(array2[i]);
|
|
19496
19538
|
const numValue = parseFloat(value);
|
|
19497
|
-
if (isNaN(num1) || isNaN(numValue)) {
|
|
19539
|
+
if (isNaN(num1) || (isNaN(numValue) && !isSingleValue1)) {
|
|
19498
19540
|
continue; // 跳过非数字元素
|
|
19499
19541
|
}
|
|
19500
19542
|
switch (operator) {
|
|
19501
19543
|
case '>':
|
|
19502
|
-
|
|
19544
|
+
if (isSingleValue1) {
|
|
19545
|
+
conditionMet = num1 > num2;
|
|
19546
|
+
}
|
|
19547
|
+
else {
|
|
19548
|
+
conditionMet = num1 > numValue;
|
|
19549
|
+
}
|
|
19503
19550
|
break;
|
|
19504
19551
|
case '<':
|
|
19505
|
-
|
|
19552
|
+
if (isSingleValue1) {
|
|
19553
|
+
conditionMet = num1 < num2;
|
|
19554
|
+
}
|
|
19555
|
+
else {
|
|
19556
|
+
conditionMet = num1 < numValue;
|
|
19557
|
+
}
|
|
19506
19558
|
break;
|
|
19507
19559
|
case '>=':
|
|
19508
|
-
|
|
19560
|
+
if (isSingleValue1) {
|
|
19561
|
+
conditionMet = num1 >= num2;
|
|
19562
|
+
}
|
|
19563
|
+
else {
|
|
19564
|
+
conditionMet = num1 >= numValue;
|
|
19565
|
+
}
|
|
19509
19566
|
break;
|
|
19510
19567
|
case '<=':
|
|
19511
|
-
|
|
19568
|
+
if (isSingleValue1) {
|
|
19569
|
+
conditionMet = num1 <= num2;
|
|
19570
|
+
}
|
|
19571
|
+
else {
|
|
19572
|
+
conditionMet = num1 <= numValue;
|
|
19573
|
+
}
|
|
19512
19574
|
break;
|
|
19513
19575
|
case '=':
|
|
19514
|
-
|
|
19576
|
+
if (isSingleValue1) {
|
|
19577
|
+
conditionMet = num1 === num2;
|
|
19578
|
+
}
|
|
19579
|
+
else {
|
|
19580
|
+
conditionMet = num1 === numValue;
|
|
19581
|
+
}
|
|
19582
|
+
break;
|
|
19583
|
+
case '±':
|
|
19584
|
+
conditionMet = num2 >= num1 - numValue && num2 <= num1 + numValue;
|
|
19515
19585
|
break;
|
|
19516
19586
|
}
|
|
19517
19587
|
}
|
|
19518
19588
|
else {
|
|
19519
|
-
//
|
|
19589
|
+
// 字符串数组:只进行相等比较(忽略operator,包括"±")[6](@ref)
|
|
19520
19590
|
conditionMet = String(array1[i]) === String(value);
|
|
19521
19591
|
}
|
|
19522
19592
|
if (conditionMet) {
|
|
19523
19593
|
validIndices.push(i);
|
|
19524
19594
|
}
|
|
19595
|
+
else {
|
|
19596
|
+
oppositeIndices.push(i);
|
|
19597
|
+
}
|
|
19525
19598
|
}
|
|
19526
19599
|
// 从第二个数组中获取对应索引的值
|
|
19527
|
-
const resultValues = validIndices
|
|
19600
|
+
const resultValues = (isOpposite == 0 ? validIndices : oppositeIndices)
|
|
19528
19601
|
.map((index) => {
|
|
19529
19602
|
// 确保索引在第二个数组范围内
|
|
19530
19603
|
if (index >= 0 && index < array2.length) {
|