소스 검색

Adding ISBLANK spreadsheet function

main
Rocketsoup 1 년 전
부모
커밋
c4bfa76efe
4개의 변경된 파일42개의 추가작업 그리고 1개의 파일을 삭제
  1. 20
    0
      js/spreadsheet.js
  2. 1
    1
      js/spreadsheet.min.js
  3. 20
    0
      php/spreadsheet.php
  4. 1
    0
      spreadsheet.md

+ 20
- 0
js/spreadsheet.js 파일 보기

@@ -459,6 +459,7 @@ class CellExpressionSet {
459 459
 			case 'FLOOR': return this.#funcFloor(args, address);
460 460
 			case 'IF': return this.#funcIf(args, address);
461 461
 			case 'IFS': return this.#funcIfs(args, address);
462
+			case 'ISBLANK': return this.#funcIsBlank(args, address);
462 463
 			case 'LN': return this.#funcLn(args, address);
463 464
 			case 'LOG': return this.#funcLog(args, address);
464 465
 			case 'LOWER': return this.#funcLower(args, address);
@@ -709,6 +710,25 @@ class CellExpressionSet {
709 710
 	}
710 711
 
711 712
 	/**
713
+	 * `IFBLANK(value)` - Returns `TRUE` if the given value is blank, otherwise
714
+	 * `FALSE`.
715
+	 *
716
+	 * @param {Array} args - raw arguments
717
+	 * @param {CellAddress} address - expression location
718
+	 * @returns {CellValue} - result
719
+	 */
720
+	#funcIsBlank(args, address) {
721
+		if (args.length !== 1) {
722
+			throw new CellEvaluationException("IFBLANK expects 1 argument");
723
+		}
724
+		const arg = this.#evaluate(args[0], address);
725
+		if (!(arg instanceof CellValue)) {
726
+			throw new CellEvaluationException("IFBLANK expcts 1 argument");
727
+		}
728
+		return CellValue.fromValue(arg.type === CellValue.TYPE_BLANK);
729
+	}
730
+
731
+	/**
712 732
 	 * `LN(value)` - Natural log.
713 733
 	 *
714 734
 	 * @param {Array} args - raw arguments

+ 1
- 1
js/spreadsheet.min.js
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 20
- 0
php/spreadsheet.php 파일 보기

@@ -418,6 +418,7 @@ class CellExpressionSet {
418 418
 			case 'FLOOR': return $this->funcFloor($args, $address);
419 419
 			case 'IF': return $this->funcIf($args, $address);
420 420
 			case 'IFS': return $this->funcIfs($args, $address);
421
+			case 'ISBLANK': return $this->funcIsBlank($args, $address);
421 422
 			case 'LN': return $this->funcLn($args, $address);
422 423
 			case 'LOG': return $this->funcLog($args, $address);
423 424
 			case 'LOWER': return $this->funcLower($args, $address);
@@ -672,6 +673,25 @@ class CellExpressionSet {
672 673
 	}
673 674
 
674 675
 	/**
676
+	 * `IFBLANK(value)` - Returns `TRUE` if the given value is blank, otherwise
677
+	 * `FALSE`.
678
+	 *
679
+	 * @param array $args  raw arguments
680
+	 * @param CellAddress $address  expression location
681
+	 * @return CellValue  result
682
+	 */
683
+	private function funcIsBlank(array $args, CellAddress $address): CellValue {
684
+		if (sizeof($args) !== 1) {
685
+			throw new CellEvaluationException("IFBLANK expects 1 argument");
686
+		}
687
+		$arg = $this->evaluate($args[0], $address);
688
+		if (!($arg instanceof CellValue)) {
689
+			throw new CellEvaluationException("IFBLANK expcts 1 argument");
690
+		}
691
+		return CellValue::fromValue($arg->type === CellValue::TYPE_BLANK);
692
+	}
693
+
694
+	/**
675 695
 	 * `LN(value)` - Natural log.
676 696
 	 *
677 697
 	 * @param array $args  raw arguments

+ 1
- 0
spreadsheet.md 파일 보기

@@ -66,6 +66,7 @@ Calculations can be grouped in parentheses to affect evaluation order.
66 66
 | `FLOOR(`_x_`)` | Rounds a value down |
67 67
 | `IF(`_test_`,` _trueval_`,` _falseval_`)` | Returns _trueval_ if _test_ evaluates to `TRUE`, otherwise returns _falseval_.
68 68
 | `IFS(`_test1_`,` _val1_`,` _test2_`,` _val2_`,` ... `,` _fallbackval_`)` | Performs multiple if tests. If _test1_ is `TRUE`, returns _val1_. If _test2_ is `TRUE`, returns _val2_. Etc. If no tests are `TRUE`, the final _fallbackval_ is returned. Takes an odd number of arguments of 3 or more. |
69
+| `ISBLANK(`_x_`)` | True if the value or cell is blank |
69 70
 | `LN(`_x_`)` | Natural logarithm |
70 71
 | `LOG(`_x_`,[` _base_`])` | Logarithm with a given _base_, or 10 if _base_ omitted |
71 72
 | `LOWER(`_x_`)` | Lowercase of a text value |

Loading…
취소
저장