NamedFormula.php 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet;
  3. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  4. class NamedFormula extends DefinedName
  5. {
  6. /**
  7. * Create a new Named Formula.
  8. */
  9. public function __construct(
  10. string $name,
  11. ?Worksheet $worksheet = null,
  12. ?string $formula = null,
  13. bool $localOnly = false,
  14. ?Worksheet $scope = null
  15. ) {
  16. // Validate data
  17. if (!isset($formula)) {
  18. throw new Exception('You must specify a Formula value for a Named Formula');
  19. }
  20. parent::__construct($name, $worksheet, $formula, $localOnly, $scope);
  21. }
  22. /**
  23. * Get the formula value.
  24. */
  25. public function getFormula(): string
  26. {
  27. return $this->value;
  28. }
  29. /**
  30. * Set the formula value.
  31. */
  32. public function setFormula(string $formula): self
  33. {
  34. if (!empty($formula)) {
  35. $this->value = $formula;
  36. }
  37. return $this;
  38. }
  39. }