Browse Source

Adding ISBLANK spreadsheet function

main
Rocketsoup 1 year ago
parent
commit
c4bfa76efe
4 changed files with 42 additions and 1 deletions
  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 View File

459
 			case 'FLOOR': return this.#funcFloor(args, address);
459
 			case 'FLOOR': return this.#funcFloor(args, address);
460
 			case 'IF': return this.#funcIf(args, address);
460
 			case 'IF': return this.#funcIf(args, address);
461
 			case 'IFS': return this.#funcIfs(args, address);
461
 			case 'IFS': return this.#funcIfs(args, address);
462
+			case 'ISBLANK': return this.#funcIsBlank(args, address);
462
 			case 'LN': return this.#funcLn(args, address);
463
 			case 'LN': return this.#funcLn(args, address);
463
 			case 'LOG': return this.#funcLog(args, address);
464
 			case 'LOG': return this.#funcLog(args, address);
464
 			case 'LOWER': return this.#funcLower(args, address);
465
 			case 'LOWER': return this.#funcLower(args, address);
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
 	 * `LN(value)` - Natural log.
732
 	 * `LN(value)` - Natural log.
713
 	 *
733
 	 *
714
 	 * @param {Array} args - raw arguments
734
 	 * @param {Array} args - raw arguments

+ 1
- 1
js/spreadsheet.min.js
File diff suppressed because it is too large
View File


+ 20
- 0
php/spreadsheet.php View File

418
 			case 'FLOOR': return $this->funcFloor($args, $address);
418
 			case 'FLOOR': return $this->funcFloor($args, $address);
419
 			case 'IF': return $this->funcIf($args, $address);
419
 			case 'IF': return $this->funcIf($args, $address);
420
 			case 'IFS': return $this->funcIfs($args, $address);
420
 			case 'IFS': return $this->funcIfs($args, $address);
421
+			case 'ISBLANK': return $this->funcIsBlank($args, $address);
421
 			case 'LN': return $this->funcLn($args, $address);
422
 			case 'LN': return $this->funcLn($args, $address);
422
 			case 'LOG': return $this->funcLog($args, $address);
423
 			case 'LOG': return $this->funcLog($args, $address);
423
 			case 'LOWER': return $this->funcLower($args, $address);
424
 			case 'LOWER': return $this->funcLower($args, $address);
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
 	 * `LN(value)` - Natural log.
695
 	 * `LN(value)` - Natural log.
676
 	 *
696
 	 *
677
 	 * @param array $args  raw arguments
697
 	 * @param array $args  raw arguments

+ 1
- 0
spreadsheet.md View File

66
 | `FLOOR(`_x_`)` | Rounds a value down |
66
 | `FLOOR(`_x_`)` | Rounds a value down |
67
 | `IF(`_test_`,` _trueval_`,` _falseval_`)` | Returns _trueval_ if _test_ evaluates to `TRUE`, otherwise returns _falseval_.
67
 | `IF(`_test_`,` _trueval_`,` _falseval_`)` | Returns _trueval_ if _test_ evaluates to `TRUE`, otherwise returns _falseval_.
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. |
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
 | `LN(`_x_`)` | Natural logarithm |
70
 | `LN(`_x_`)` | Natural logarithm |
70
 | `LOG(`_x_`,[` _base_`])` | Logarithm with a given _base_, or 10 if _base_ omitted |
71
 | `LOG(`_x_`,[` _base_`])` | Logarithm with a given _base_, or 10 if _base_ omitted |
71
 | `LOWER(`_x_`)` | Lowercase of a text value |
72
 | `LOWER(`_x_`)` | Lowercase of a text value |

Loading…
Cancel
Save