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.cjs.js
CHANGED
|
@@ -19471,7 +19471,7 @@ const FormulaUtils = {
|
|
|
19471
19471
|
optional: false,
|
|
19472
19472
|
},
|
|
19473
19473
|
{
|
|
19474
|
-
name: '
|
|
19474
|
+
name: '比较大小或比较相等的字符串,格式为:“>”、“<”、“>=”、“<=”、“=”、“±”',
|
|
19475
19475
|
repeatable: false,
|
|
19476
19476
|
optional: false,
|
|
19477
19477
|
},
|
|
@@ -19485,68 +19485,141 @@ 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
|
-
|
|
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 {
|
|
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为数组,则设置其取第一个值
|
|
19515
|
+
if (Array.isArray(operator) && operator.length > 0) {
|
|
19516
|
+
operator = operator[0];
|
|
19517
|
+
}
|
|
19518
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
19519
|
+
value = value[0];
|
|
19520
|
+
}
|
|
19521
|
+
if (Array.isArray(delimiter) && delimiter.length > 0) {
|
|
19522
|
+
delimiter = delimiter[0];
|
|
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;
|
|
19496
19537
|
// 参数基础校验
|
|
19497
19538
|
if (!Array.isArray(array1) ||
|
|
19498
19539
|
!Array.isArray(array2) ||
|
|
19499
|
-
array1.length !== array2.length ||
|
|
19540
|
+
// array1.length !== array2.length ||
|
|
19500
19541
|
typeof operator !== 'string' ||
|
|
19501
19542
|
typeof delimiter !== 'string') {
|
|
19502
19543
|
return '/';
|
|
19503
19544
|
}
|
|
19504
19545
|
// 验证operator参数的有效性
|
|
19505
|
-
const validOperators = ['>', '<', '>=', '<=', '='];
|
|
19546
|
+
const validOperators = ['>', '<', '>=', '<=', '=', '±'];
|
|
19506
19547
|
if (!validOperators.includes(operator)) {
|
|
19507
19548
|
return '/';
|
|
19508
19549
|
}
|
|
19509
19550
|
// 判断第一个数组的元素类型
|
|
19510
19551
|
const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
|
|
19511
|
-
//
|
|
19512
|
-
const validIndices = [];
|
|
19513
|
-
for (let i = 0; i <
|
|
19552
|
+
// 收集满足条件的索引和不满足条件的索引
|
|
19553
|
+
const validIndices = [], oppositeIndices = [];
|
|
19554
|
+
for (let i = 0; i < array2.length; i++) {
|
|
19514
19555
|
let conditionMet = false;
|
|
19515
19556
|
if (isNumericArray) {
|
|
19516
|
-
//
|
|
19517
|
-
const num1 = parseFloat(array1[i]);
|
|
19557
|
+
// 第一个参数为单值的时候,取第一个值
|
|
19558
|
+
const num1 = isSingleValue1 ? parseFloat(array1[0]) : parseFloat(array1[i]);
|
|
19559
|
+
const num2 = parseFloat(array2[i]);
|
|
19518
19560
|
const numValue = parseFloat(value);
|
|
19519
|
-
if (isNaN(num1) || isNaN(numValue)) {
|
|
19561
|
+
if (isNaN(num1) || (isNaN(numValue) && !isSingleValue1)) {
|
|
19520
19562
|
continue; // 跳过非数字元素
|
|
19521
19563
|
}
|
|
19522
19564
|
switch (operator) {
|
|
19523
19565
|
case '>':
|
|
19524
|
-
|
|
19566
|
+
if (isSingleValue1) {
|
|
19567
|
+
conditionMet = num1 > num2;
|
|
19568
|
+
}
|
|
19569
|
+
else {
|
|
19570
|
+
conditionMet = num1 > numValue;
|
|
19571
|
+
}
|
|
19525
19572
|
break;
|
|
19526
19573
|
case '<':
|
|
19527
|
-
|
|
19574
|
+
if (isSingleValue1) {
|
|
19575
|
+
conditionMet = num1 < num2;
|
|
19576
|
+
}
|
|
19577
|
+
else {
|
|
19578
|
+
conditionMet = num1 < numValue;
|
|
19579
|
+
}
|
|
19528
19580
|
break;
|
|
19529
19581
|
case '>=':
|
|
19530
|
-
|
|
19582
|
+
if (isSingleValue1) {
|
|
19583
|
+
conditionMet = num1 >= num2;
|
|
19584
|
+
}
|
|
19585
|
+
else {
|
|
19586
|
+
conditionMet = num1 >= numValue;
|
|
19587
|
+
}
|
|
19531
19588
|
break;
|
|
19532
19589
|
case '<=':
|
|
19533
|
-
|
|
19590
|
+
if (isSingleValue1) {
|
|
19591
|
+
conditionMet = num1 <= num2;
|
|
19592
|
+
}
|
|
19593
|
+
else {
|
|
19594
|
+
conditionMet = num1 <= numValue;
|
|
19595
|
+
}
|
|
19534
19596
|
break;
|
|
19535
19597
|
case '=':
|
|
19536
|
-
|
|
19598
|
+
if (isSingleValue1) {
|
|
19599
|
+
conditionMet = num1 === num2;
|
|
19600
|
+
}
|
|
19601
|
+
else {
|
|
19602
|
+
conditionMet = num1 === numValue;
|
|
19603
|
+
}
|
|
19604
|
+
break;
|
|
19605
|
+
case '±':
|
|
19606
|
+
conditionMet = num2 >= num1 - numValue && num2 <= num1 + numValue;
|
|
19537
19607
|
break;
|
|
19538
19608
|
}
|
|
19539
19609
|
}
|
|
19540
19610
|
else {
|
|
19541
|
-
//
|
|
19611
|
+
// 字符串数组:只进行相等比较(忽略operator,包括"±")[6](@ref)
|
|
19542
19612
|
conditionMet = String(array1[i]) === String(value);
|
|
19543
19613
|
}
|
|
19544
19614
|
if (conditionMet) {
|
|
19545
19615
|
validIndices.push(i);
|
|
19546
19616
|
}
|
|
19617
|
+
else {
|
|
19618
|
+
oppositeIndices.push(i);
|
|
19619
|
+
}
|
|
19547
19620
|
}
|
|
19548
19621
|
// 从第二个数组中获取对应索引的值
|
|
19549
|
-
const resultValues = validIndices
|
|
19622
|
+
const resultValues = (isOpposite == 0 ? validIndices : oppositeIndices)
|
|
19550
19623
|
.map((index) => {
|
|
19551
19624
|
// 确保索引在第二个数组范围内
|
|
19552
19625
|
if (index >= 0 && index < array2.length) {
|