rapid-spreadjs 1.0.59 → 1.0.61

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 CHANGED
@@ -12856,6 +12856,7 @@ const FormulaUtils = {
12856
12856
  //自定义函数逻辑
12857
12857
  cusFun.prototype.evaluate = function () {
12858
12858
  // 获取该自定义公式被引用单元格的索引
12859
+ console.log('所有参数:', arguments);
12859
12860
  /**
12860
12861
  * 说明:
12861
12862
  * 如果isContext=true,则arguments的第一个参数为上下文参数,后面的参数才是自定义参数真正传入的参数
@@ -19375,6 +19376,195 @@ const FormulaUtils = {
19375
19376
  return d;
19376
19377
  },
19377
19378
  },
19379
+ {
19380
+ funName: 'YJDXPD',
19381
+ funDesc: '单项判定',
19382
+ funDefaultVal: null,
19383
+ isAcceptArea: true,
19384
+ funParams: [
19385
+ {
19386
+ name: '判定范围,格式如:-2,2、-2~2或±2',
19387
+ repeatable: false,
19388
+ optional: false,
19389
+ },
19390
+ {
19391
+ name: '判定值,如:1',
19392
+ repeatable: false,
19393
+ optional: false,
19394
+ },
19395
+ ],
19396
+ funCallback: (spread, sheet, retData) => {
19397
+ //如果传递的参数小于2个,则返回空字符串
19398
+ if (retData.allCellVals.length < 2) {
19399
+ return '';
19400
+ }
19401
+ try {
19402
+ const rangeStr = retData.allCellVals[0], num = retData.allCellVals[1];
19403
+ // 参数基础校验
19404
+ if (typeof rangeStr !== 'string' || typeof num !== 'number' || isNaN(num)) {
19405
+ return '/';
19406
+ }
19407
+ // 去除字符串中的空格
19408
+ const cleanStr = rangeStr.replace(/\s/g, '');
19409
+ let min, max;
19410
+ // 处理三种格式
19411
+ if (cleanStr.includes(',')) {
19412
+ // 格式:"-2,2"
19413
+ const parts = cleanStr.split(',');
19414
+ if (parts.length !== 2)
19415
+ return '/';
19416
+ min = parseFloat(parts[0]);
19417
+ max = parseFloat(parts[1]);
19418
+ }
19419
+ else if (cleanStr.includes('~')) {
19420
+ // 格式:"-2~2"
19421
+ const parts = cleanStr.split('~');
19422
+ if (parts.length !== 2)
19423
+ return '/';
19424
+ min = parseFloat(parts[0]);
19425
+ max = parseFloat(parts[1]);
19426
+ }
19427
+ else if (cleanStr.includes('±')) {
19428
+ // 格式:"±2"
19429
+ const valueStr = cleanStr.replace('±', '');
19430
+ const value = parseFloat(valueStr);
19431
+ if (isNaN(value))
19432
+ return '/';
19433
+ min = -value;
19434
+ max = value;
19435
+ }
19436
+ else {
19437
+ // 不是三种指定格式之一
19438
+ return '/';
19439
+ }
19440
+ // 检查解析结果是否有效
19441
+ if (isNaN(min) || isNaN(max)) {
19442
+ return '/';
19443
+ }
19444
+ // 判断数字是否在范围内
19445
+ if (num >= min && num <= max) {
19446
+ return '合格';
19447
+ }
19448
+ else {
19449
+ return '不合格';
19450
+ }
19451
+ }
19452
+ catch (error) {
19453
+ // 任何错误都返回"/"
19454
+ return '/';
19455
+ }
19456
+ },
19457
+ },
19458
+ {
19459
+ funName: 'YJTEXTJOIN',
19460
+ funDesc: '此函数将多个区域和/或字符串的文本组合起来,并包括你在要组合的各文本值之间指定的分隔符。',
19461
+ funDefaultVal: null,
19462
+ isAcceptArea: true,
19463
+ funParams: [
19464
+ {
19465
+ name: '需要用作判断的数字数组或字符串数组',
19466
+ repeatable: false,
19467
+ optional: false,
19468
+ },
19469
+ {
19470
+ name: '返回值的数组',
19471
+ repeatable: false,
19472
+ optional: false,
19473
+ },
19474
+ {
19475
+ name: '比较大小或比较相等的字符串,格式为:“>”、“<”、“>=”、“<=”、“=”',
19476
+ repeatable: false,
19477
+ optional: false,
19478
+ },
19479
+ {
19480
+ name: '比较的值,类型为数字类型或字符串类型,如:3或“合格”',
19481
+ repeatable: false,
19482
+ optional: false,
19483
+ },
19484
+ {
19485
+ name: '返回值的分隔符,默认为:,',
19486
+ repeatable: false,
19487
+ optional: false,
19488
+ },
19489
+ ],
19490
+ funCallback: (spread, sheet, retData) => {
19491
+ //如果传递的参数小于5个,则返回空字符串
19492
+ if (retData.allCellValsEw.length < 5) {
19493
+ return '';
19494
+ }
19495
+ const array1 = retData.allCellValsEw[0], array2 = retData.allCellValsEw[1], operator = retData.allCellValsEw[2], value = retData.allCellValsEw[3], delimiter = retData.allCellValsEw[4];
19496
+ try {
19497
+ // 参数基础校验
19498
+ if (!Array.isArray(array1) ||
19499
+ !Array.isArray(array2) ||
19500
+ array1.length !== array2.length ||
19501
+ typeof operator !== 'string' ||
19502
+ typeof delimiter !== 'string') {
19503
+ return '/';
19504
+ }
19505
+ // 验证operator参数的有效性
19506
+ const validOperators = ['>', '<', '>=', '<=', '='];
19507
+ if (!validOperators.includes(operator)) {
19508
+ return '/';
19509
+ }
19510
+ // 判断第一个数组的元素类型
19511
+ const isNumericArray = array1.length > 0 && (typeof array1[0] === 'number' || !isNaN(parseFloat(array1[0])));
19512
+ // 收集满足条件的索引
19513
+ const validIndices = [];
19514
+ for (let i = 0; i < array1.length; i++) {
19515
+ let conditionMet = false;
19516
+ if (isNumericArray) {
19517
+ // 数字数组:使用指定的比较运算符
19518
+ const num1 = parseFloat(array1[i]);
19519
+ const numValue = parseFloat(value);
19520
+ if (isNaN(num1) || isNaN(numValue)) {
19521
+ continue; // 跳过非数字元素
19522
+ }
19523
+ switch (operator) {
19524
+ case '>':
19525
+ conditionMet = num1 > numValue;
19526
+ break;
19527
+ case '<':
19528
+ conditionMet = num1 < numValue;
19529
+ break;
19530
+ case '>=':
19531
+ conditionMet = num1 >= numValue;
19532
+ break;
19533
+ case '<=':
19534
+ conditionMet = num1 <= numValue;
19535
+ break;
19536
+ case '=':
19537
+ conditionMet = num1 === numValue;
19538
+ break;
19539
+ }
19540
+ }
19541
+ else {
19542
+ // 字符串数组:只进行相等比较
19543
+ conditionMet = String(array1[i]) === String(value);
19544
+ }
19545
+ if (conditionMet) {
19546
+ validIndices.push(i);
19547
+ }
19548
+ }
19549
+ // 从第二个数组中获取对应索引的值
19550
+ const resultValues = validIndices
19551
+ .map((index) => {
19552
+ // 确保索引在第二个数组范围内
19553
+ if (index >= 0 && index < array2.length) {
19554
+ return String(array2[index]);
19555
+ }
19556
+ return '';
19557
+ })
19558
+ .filter((val) => val !== ''); // 过滤空值
19559
+ // 使用指定的分隔符连接结果[2,3,5](@ref)
19560
+ return resultValues.join(delimiter);
19561
+ }
19562
+ catch (error) {
19563
+ // 任何错误都返回"/"
19564
+ return '/';
19565
+ }
19566
+ },
19567
+ },
19378
19568
  {
19379
19569
  funName: 'YJTREND',
19380
19570
  funDesc: '返回线性回归拟合线的一组纵坐标值(y值)',