rapid-spreadjs 1.0.67 → 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 +78 -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 +78 -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.cjs.js
CHANGED
|
@@ -19485,15 +19485,33 @@ const FormulaUtils = {
|
|
|
19485
19485
|
repeatable: false,
|
|
19486
19486
|
optional: false,
|
|
19487
19487
|
},
|
|
19488
|
+
{
|
|
19489
|
+
name: '是否返回相反的结果(传数字的1或0,0:满足条件的结果、1:相反的结果),默认为:0',
|
|
19490
|
+
repeatable: false,
|
|
19491
|
+
optional: false,
|
|
19492
|
+
},
|
|
19488
19493
|
],
|
|
19489
19494
|
funCallback: (spread, sheet, retData) => {
|
|
19490
|
-
//如果传递的参数小于
|
|
19491
|
-
if (retData.allCellValsEw.length <
|
|
19495
|
+
//如果传递的参数小于6个,则返回空字符串
|
|
19496
|
+
if (retData.allCellValsEw.length < 6) {
|
|
19492
19497
|
return '';
|
|
19493
19498
|
}
|
|
19494
|
-
let array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4];
|
|
19499
|
+
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];
|
|
19495
19500
|
try {
|
|
19496
|
-
//
|
|
19501
|
+
// 处理array1和array2的默认值
|
|
19502
|
+
if (array1 == null || array1 == undefined || (typeof array1 == 'string' && array1.trim().length == 0)) {
|
|
19503
|
+
array1 = [];
|
|
19504
|
+
}
|
|
19505
|
+
if (array2 == null || array2 == undefined || (typeof array2 == 'string' && array2.trim().length == 0)) {
|
|
19506
|
+
array2 = [];
|
|
19507
|
+
}
|
|
19508
|
+
if (typeof array1 == 'string' && array1.trim().length > 0) {
|
|
19509
|
+
array1 = [array1];
|
|
19510
|
+
}
|
|
19511
|
+
if (typeof array2 == 'string' && array2.trim().length > 0) {
|
|
19512
|
+
array2 = [array2];
|
|
19513
|
+
}
|
|
19514
|
+
// 如果operator、value、delimiter、isOpposite为数组,则设置其取第一个值
|
|
19497
19515
|
if (Array.isArray(operator) && operator.length > 0) {
|
|
19498
19516
|
operator = operator[0];
|
|
19499
19517
|
}
|
|
@@ -19503,10 +19521,23 @@ const FormulaUtils = {
|
|
|
19503
19521
|
if (Array.isArray(delimiter) && delimiter.length > 0) {
|
|
19504
19522
|
delimiter = delimiter[0];
|
|
19505
19523
|
}
|
|
19524
|
+
if (Array.isArray(isOpposite) && isOpposite.length > 0) {
|
|
19525
|
+
isOpposite = isOpposite[0];
|
|
19526
|
+
}
|
|
19527
|
+
// 设置isOpposite的默认值
|
|
19528
|
+
if (isOpposite == '1' || isOpposite == '0') {
|
|
19529
|
+
isOpposite = parseInt(isOpposite);
|
|
19530
|
+
}
|
|
19531
|
+
if (isOpposite != 0 && isOpposite != 1) {
|
|
19532
|
+
isOpposite = 0;
|
|
19533
|
+
}
|
|
19534
|
+
// TODO:暂定此情况
|
|
19535
|
+
// 第一个参数是否为单值(array1为一个值的时候,此时array2的所有元素可能需要参与计算,满足要求的就返回array2中的值)
|
|
19536
|
+
const isSingleValue1 = array2.length > array1.length && array1.length == 1;
|
|
19506
19537
|
// 参数基础校验
|
|
19507
19538
|
if (!Array.isArray(array1) ||
|
|
19508
19539
|
!Array.isArray(array2) ||
|
|
19509
|
-
array1.length !== array2.length ||
|
|
19540
|
+
// array1.length !== array2.length ||
|
|
19510
19541
|
typeof operator !== 'string' ||
|
|
19511
19542
|
typeof delimiter !== 'string') {
|
|
19512
19543
|
return '/';
|
|
@@ -19518,36 +19549,61 @@ const FormulaUtils = {
|
|
|
19518
19549
|
}
|
|
19519
19550
|
// 判断第一个数组的元素类型
|
|
19520
19551
|
const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
|
|
19521
|
-
//
|
|
19522
|
-
const validIndices = [];
|
|
19523
|
-
for (let i = 0; i <
|
|
19552
|
+
// 收集满足条件的索引和不满足条件的索引
|
|
19553
|
+
const validIndices = [], oppositeIndices = [];
|
|
19554
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19524
19555
|
let conditionMet = false;
|
|
19525
19556
|
if (isNumericArray) {
|
|
19526
|
-
//
|
|
19527
|
-
const num1 = parseFloat(array1[i]);
|
|
19557
|
+
// 第一个参数为单值的时候,取第一个值
|
|
19558
|
+
const num1 = isSingleValue1 ? parseFloat(array1[0]) : parseFloat(array1[i]);
|
|
19559
|
+
const num2 = parseFloat(array2[i]);
|
|
19528
19560
|
const numValue = parseFloat(value);
|
|
19529
|
-
if (isNaN(num1) || isNaN(numValue)) {
|
|
19561
|
+
if (isNaN(num1) || (isNaN(numValue) && !isSingleValue1)) {
|
|
19530
19562
|
continue; // 跳过非数字元素
|
|
19531
19563
|
}
|
|
19532
19564
|
switch (operator) {
|
|
19533
19565
|
case '>':
|
|
19534
|
-
|
|
19566
|
+
if (isSingleValue1) {
|
|
19567
|
+
conditionMet = num1 > num2;
|
|
19568
|
+
}
|
|
19569
|
+
else {
|
|
19570
|
+
conditionMet = num1 > numValue;
|
|
19571
|
+
}
|
|
19535
19572
|
break;
|
|
19536
19573
|
case '<':
|
|
19537
|
-
|
|
19574
|
+
if (isSingleValue1) {
|
|
19575
|
+
conditionMet = num1 < num2;
|
|
19576
|
+
}
|
|
19577
|
+
else {
|
|
19578
|
+
conditionMet = num1 < numValue;
|
|
19579
|
+
}
|
|
19538
19580
|
break;
|
|
19539
19581
|
case '>=':
|
|
19540
|
-
|
|
19582
|
+
if (isSingleValue1) {
|
|
19583
|
+
conditionMet = num1 >= num2;
|
|
19584
|
+
}
|
|
19585
|
+
else {
|
|
19586
|
+
conditionMet = num1 >= numValue;
|
|
19587
|
+
}
|
|
19541
19588
|
break;
|
|
19542
19589
|
case '<=':
|
|
19543
|
-
|
|
19590
|
+
if (isSingleValue1) {
|
|
19591
|
+
conditionMet = num1 <= num2;
|
|
19592
|
+
}
|
|
19593
|
+
else {
|
|
19594
|
+
conditionMet = num1 <= numValue;
|
|
19595
|
+
}
|
|
19544
19596
|
break;
|
|
19545
19597
|
case '=':
|
|
19546
|
-
|
|
19598
|
+
if (isSingleValue1) {
|
|
19599
|
+
conditionMet = num1 === num2;
|
|
19600
|
+
}
|
|
19601
|
+
else {
|
|
19602
|
+
conditionMet = num1 === numValue;
|
|
19603
|
+
}
|
|
19547
19604
|
break;
|
|
19548
19605
|
case '±':
|
|
19549
|
-
|
|
19550
|
-
conditionMet = num1 >= -numValue && num1 <= numValue;
|
|
19606
|
+
conditionMet = num2 >= num1 - numValue && num2 <= num1 + numValue;
|
|
19551
19607
|
break;
|
|
19552
19608
|
}
|
|
19553
19609
|
}
|
|
@@ -19558,9 +19614,12 @@ const FormulaUtils = {
|
|
|
19558
19614
|
if (conditionMet) {
|
|
19559
19615
|
validIndices.push(i);
|
|
19560
19616
|
}
|
|
19617
|
+
else {
|
|
19618
|
+
oppositeIndices.push(i);
|
|
19619
|
+
}
|
|
19561
19620
|
}
|
|
19562
19621
|
// 从第二个数组中获取对应索引的值
|
|
19563
|
-
const resultValues = validIndices
|
|
19622
|
+
const resultValues = (isOpposite == 0 ? validIndices : oppositeIndices)
|
|
19564
19623
|
.map((index) => {
|
|
19565
19624
|
// 确保索引在第二个数组范围内
|
|
19566
19625
|
if (index >= 0 && index < array2.length) {
|