Cell.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Cell;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
  5. use PhpOffice\PhpSpreadsheet\Collection\Cells;
  6. use PhpOffice\PhpSpreadsheet\Exception;
  7. use PhpOffice\PhpSpreadsheet\RichText\RichText;
  8. use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
  9. use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
  10. use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellStyleAssessor;
  11. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  12. use PhpOffice\PhpSpreadsheet\Style\Style;
  13. use PhpOffice\PhpSpreadsheet\Worksheet\Table;
  14. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  15. class Cell
  16. {
  17. /**
  18. * Value binder to use.
  19. *
  20. * @var IValueBinder
  21. */
  22. private static $valueBinder;
  23. /**
  24. * Value of the cell.
  25. *
  26. * @var mixed
  27. */
  28. private $value;
  29. /**
  30. * Calculated value of the cell (used for caching)
  31. * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
  32. * create the original spreadsheet file.
  33. * Note that this value is not guaranteed to reflect the actual calculated value because it is
  34. * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
  35. * values used by the formula have changed since it was last calculated.
  36. *
  37. * @var mixed
  38. */
  39. private $calculatedValue;
  40. /**
  41. * Type of the cell data.
  42. *
  43. * @var string
  44. */
  45. private $dataType;
  46. /**
  47. * The collection of cells that this cell belongs to (i.e. The Cell Collection for the parent Worksheet).
  48. *
  49. * @var ?Cells
  50. */
  51. private $parent;
  52. /**
  53. * Index to the cellXf reference for the styling of this cell.
  54. *
  55. * @var int
  56. */
  57. private $xfIndex = 0;
  58. /**
  59. * Attributes of the formula.
  60. *
  61. * @var mixed
  62. */
  63. private $formulaAttributes;
  64. /** @var IgnoredErrors */
  65. private $ignoredErrors;
  66. /**
  67. * Update the cell into the cell collection.
  68. *
  69. * @return $this
  70. */
  71. public function updateInCollection(): self
  72. {
  73. $parent = $this->parent;
  74. if ($parent === null) {
  75. throw new Exception('Cannot update when cell is not bound to a worksheet');
  76. }
  77. $parent->update($this);
  78. return $this;
  79. }
  80. public function detach(): void
  81. {
  82. $this->parent = null;
  83. }
  84. public function attach(Cells $parent): void
  85. {
  86. $this->parent = $parent;
  87. }
  88. /**
  89. * Create a new Cell.
  90. *
  91. * @param mixed $value
  92. */
  93. public function __construct($value, ?string $dataType, Worksheet $worksheet)
  94. {
  95. // Initialise cell value
  96. $this->value = $value;
  97. // Set worksheet cache
  98. $this->parent = $worksheet->getCellCollection();
  99. // Set datatype?
  100. if ($dataType !== null) {
  101. if ($dataType == DataType::TYPE_STRING2) {
  102. $dataType = DataType::TYPE_STRING;
  103. }
  104. $this->dataType = $dataType;
  105. } elseif (self::getValueBinder()->bindValue($this, $value) === false) {
  106. throw new Exception('Value could not be bound to cell.');
  107. }
  108. $this->ignoredErrors = new IgnoredErrors();
  109. }
  110. /**
  111. * Get cell coordinate column.
  112. *
  113. * @return string
  114. */
  115. public function getColumn()
  116. {
  117. $parent = $this->parent;
  118. if ($parent === null) {
  119. throw new Exception('Cannot get column when cell is not bound to a worksheet');
  120. }
  121. return $parent->getCurrentColumn();
  122. }
  123. /**
  124. * Get cell coordinate row.
  125. *
  126. * @return int
  127. */
  128. public function getRow()
  129. {
  130. $parent = $this->parent;
  131. if ($parent === null) {
  132. throw new Exception('Cannot get row when cell is not bound to a worksheet');
  133. }
  134. return $parent->getCurrentRow();
  135. }
  136. /**
  137. * Get cell coordinate.
  138. *
  139. * @return string
  140. */
  141. public function getCoordinate()
  142. {
  143. $parent = $this->parent;
  144. if ($parent !== null) {
  145. $coordinate = $parent->getCurrentCoordinate();
  146. } else {
  147. $coordinate = null;
  148. }
  149. if ($coordinate === null) {
  150. throw new Exception('Coordinate no longer exists');
  151. }
  152. return $coordinate;
  153. }
  154. /**
  155. * Get cell value.
  156. *
  157. * @return mixed
  158. */
  159. public function getValue()
  160. {
  161. return $this->value;
  162. }
  163. /**
  164. * Get cell value with formatting.
  165. */
  166. public function getFormattedValue(): string
  167. {
  168. return (string) NumberFormat::toFormattedString(
  169. $this->getCalculatedValue(),
  170. (string) $this->getStyle()->getNumberFormat()->getFormatCode()
  171. );
  172. }
  173. /**
  174. * @param mixed $oldValue
  175. * @param mixed $newValue
  176. */
  177. protected static function updateIfCellIsTableHeader(?Worksheet $workSheet, self $cell, $oldValue, $newValue): void
  178. {
  179. if (StringHelper::strToLower($oldValue ?? '') === StringHelper::strToLower($newValue ?? '') || $workSheet === null) {
  180. return;
  181. }
  182. foreach ($workSheet->getTableCollection() as $table) {
  183. /** @var Table $table */
  184. if ($cell->isInRange($table->getRange())) {
  185. $rangeRowsColumns = Coordinate::getRangeBoundaries($table->getRange());
  186. if ($cell->getRow() === (int) $rangeRowsColumns[0][1]) {
  187. Table\Column::updateStructuredReferences($workSheet, $oldValue, $newValue);
  188. }
  189. return;
  190. }
  191. }
  192. }
  193. /**
  194. * Set cell value.
  195. *
  196. * Sets the value for a cell, automatically determining the datatype using the value binder
  197. *
  198. * @param mixed $value Value
  199. * @param null|IValueBinder $binder Value Binder to override the currently set Value Binder
  200. *
  201. * @throws Exception
  202. *
  203. * @return $this
  204. */
  205. public function setValue($value, ?IValueBinder $binder = null): self
  206. {
  207. $binder ??= self::getValueBinder();
  208. if (!$binder->bindValue($this, $value)) {
  209. throw new Exception('Value could not be bound to cell.');
  210. }
  211. return $this;
  212. }
  213. /**
  214. * Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder).
  215. *
  216. * @param mixed $value Value
  217. * @param string $dataType Explicit data type, see DataType::TYPE_*
  218. * Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
  219. * method, then it is your responsibility as an end-user developer to validate that the value and
  220. * the datatype match.
  221. * If you do mismatch value and datatype, then the value you enter may be changed to match the datatype
  222. * that you specify.
  223. *
  224. * @return Cell
  225. */
  226. public function setValueExplicit($value, string $dataType = DataType::TYPE_STRING)
  227. {
  228. $oldValue = $this->value;
  229. // set the value according to data type
  230. switch ($dataType) {
  231. case DataType::TYPE_NULL:
  232. $this->value = null;
  233. break;
  234. case DataType::TYPE_STRING2:
  235. $dataType = DataType::TYPE_STRING;
  236. // no break
  237. case DataType::TYPE_STRING:
  238. // Synonym for string
  239. case DataType::TYPE_INLINE:
  240. // Rich text
  241. $this->value = DataType::checkString($value);
  242. break;
  243. case DataType::TYPE_NUMERIC:
  244. if (is_string($value) && !is_numeric($value)) {
  245. throw new Exception('Invalid numeric value for datatype Numeric');
  246. }
  247. $this->value = 0 + $value;
  248. break;
  249. case DataType::TYPE_FORMULA:
  250. $this->value = (string) $value;
  251. break;
  252. case DataType::TYPE_BOOL:
  253. $this->value = (bool) $value;
  254. break;
  255. case DataType::TYPE_ISO_DATE:
  256. $this->value = SharedDate::convertIsoDate($value);
  257. $dataType = DataType::TYPE_NUMERIC;
  258. break;
  259. case DataType::TYPE_ERROR:
  260. $this->value = DataType::checkErrorCode($value);
  261. break;
  262. default:
  263. throw new Exception('Invalid datatype: ' . $dataType);
  264. }
  265. // set the datatype
  266. $this->dataType = $dataType;
  267. $this->updateInCollection();
  268. $cellCoordinate = $this->getCoordinate();
  269. self::updateIfCellIsTableHeader($this->getParent()->getParent(), $this, $oldValue, $value); // @phpstan-ignore-line
  270. return $this->getParent()->get($cellCoordinate); // @phpstan-ignore-line
  271. }
  272. public const CALCULATE_DATE_TIME_ASIS = 0;
  273. public const CALCULATE_DATE_TIME_FLOAT = 1;
  274. public const CALCULATE_TIME_FLOAT = 2;
  275. /** @var int */
  276. private static $calculateDateTimeType = self::CALCULATE_DATE_TIME_ASIS;
  277. public static function getCalculateDateTimeType(): int
  278. {
  279. return self::$calculateDateTimeType;
  280. }
  281. public static function setCalculateDateTimeType(int $calculateDateTimeType): void
  282. {
  283. switch ($calculateDateTimeType) {
  284. case self::CALCULATE_DATE_TIME_ASIS:
  285. case self::CALCULATE_DATE_TIME_FLOAT:
  286. case self::CALCULATE_TIME_FLOAT:
  287. self::$calculateDateTimeType = $calculateDateTimeType;
  288. break;
  289. default:
  290. throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception("Invalid value $calculateDateTimeType for calculated date time type");
  291. }
  292. }
  293. /**
  294. * Convert date, time, or datetime from int to float if desired.
  295. *
  296. * @param mixed $result
  297. *
  298. * @return mixed
  299. */
  300. private function convertDateTimeInt($result)
  301. {
  302. if (is_int($result)) {
  303. if (self::$calculateDateTimeType === self::CALCULATE_TIME_FLOAT) {
  304. if (SharedDate::isDateTime($this, $result, false)) {
  305. $result = (float) $result;
  306. }
  307. } elseif (self::$calculateDateTimeType === self::CALCULATE_DATE_TIME_FLOAT) {
  308. if (SharedDate::isDateTime($this, $result, true)) {
  309. $result = (float) $result;
  310. }
  311. }
  312. }
  313. return $result;
  314. }
  315. /**
  316. * Get calculated cell value.
  317. *
  318. * @param bool $resetLog Whether the calculation engine logger should be reset or not
  319. *
  320. * @return mixed
  321. */
  322. public function getCalculatedValue(bool $resetLog = true)
  323. {
  324. if ($this->dataType === DataType::TYPE_FORMULA) {
  325. try {
  326. $index = $this->getWorksheet()->getParentOrThrow()->getActiveSheetIndex();
  327. $selected = $this->getWorksheet()->getSelectedCells();
  328. $result = Calculation::getInstance(
  329. $this->getWorksheet()->getParent()
  330. )->calculateCellValue($this, $resetLog);
  331. $result = $this->convertDateTimeInt($result);
  332. $this->getWorksheet()->setSelectedCells($selected);
  333. $this->getWorksheet()->getParentOrThrow()->setActiveSheetIndex($index);
  334. // We don't yet handle array returns
  335. if (is_array($result)) {
  336. while (is_array($result)) {
  337. $result = array_shift($result);
  338. }
  339. }
  340. } catch (Exception $ex) {
  341. if (($ex->getMessage() === 'Unable to access External Workbook') && ($this->calculatedValue !== null)) {
  342. return $this->calculatedValue; // Fallback for calculations referencing external files.
  343. } elseif (preg_match('/[Uu]ndefined (name|offset: 2|array key 2)/', $ex->getMessage()) === 1) {
  344. return ExcelError::NAME();
  345. }
  346. throw new \PhpOffice\PhpSpreadsheet\Calculation\Exception(
  347. $this->getWorksheet()->getTitle() . '!' . $this->getCoordinate() . ' -> ' . $ex->getMessage(),
  348. $ex->getCode(),
  349. $ex
  350. );
  351. }
  352. if ($result === '#Not Yet Implemented') {
  353. return $this->calculatedValue; // Fallback if calculation engine does not support the formula.
  354. }
  355. return $result;
  356. } elseif ($this->value instanceof RichText) {
  357. return $this->value->getPlainText();
  358. }
  359. return $this->convertDateTimeInt($this->value);
  360. }
  361. /**
  362. * Set old calculated value (cached).
  363. *
  364. * @param mixed $originalValue Value
  365. */
  366. public function setCalculatedValue($originalValue): self
  367. {
  368. if ($originalValue !== null) {
  369. $this->calculatedValue = (is_numeric($originalValue)) ? (float) $originalValue : $originalValue;
  370. }
  371. return $this->updateInCollection();
  372. }
  373. /**
  374. * Get old calculated value (cached)
  375. * This returns the value last calculated by MS Excel or whichever spreadsheet program was used to
  376. * create the original spreadsheet file.
  377. * Note that this value is not guaranteed to reflect the actual calculated value because it is
  378. * possible that auto-calculation was disabled in the original spreadsheet, and underlying data
  379. * values used by the formula have changed since it was last calculated.
  380. *
  381. * @return mixed
  382. */
  383. public function getOldCalculatedValue()
  384. {
  385. return $this->calculatedValue;
  386. }
  387. /**
  388. * Get cell data type.
  389. */
  390. public function getDataType(): string
  391. {
  392. return $this->dataType;
  393. }
  394. /**
  395. * Set cell data type.
  396. *
  397. * @param string $dataType see DataType::TYPE_*
  398. */
  399. public function setDataType($dataType): self
  400. {
  401. if ($dataType == DataType::TYPE_STRING2) {
  402. $dataType = DataType::TYPE_STRING;
  403. }
  404. $this->dataType = $dataType;
  405. return $this->updateInCollection();
  406. }
  407. /**
  408. * Identify if the cell contains a formula.
  409. */
  410. public function isFormula(): bool
  411. {
  412. return $this->dataType === DataType::TYPE_FORMULA && $this->getStyle()->getQuotePrefix() === false;
  413. }
  414. /**
  415. * Does this cell contain Data validation rules?
  416. */
  417. public function hasDataValidation(): bool
  418. {
  419. if (!isset($this->parent)) {
  420. throw new Exception('Cannot check for data validation when cell is not bound to a worksheet');
  421. }
  422. return $this->getWorksheet()->dataValidationExists($this->getCoordinate());
  423. }
  424. /**
  425. * Get Data validation rules.
  426. */
  427. public function getDataValidation(): DataValidation
  428. {
  429. if (!isset($this->parent)) {
  430. throw new Exception('Cannot get data validation for cell that is not bound to a worksheet');
  431. }
  432. return $this->getWorksheet()->getDataValidation($this->getCoordinate());
  433. }
  434. /**
  435. * Set Data validation rules.
  436. */
  437. public function setDataValidation(?DataValidation $dataValidation = null): self
  438. {
  439. if (!isset($this->parent)) {
  440. throw new Exception('Cannot set data validation for cell that is not bound to a worksheet');
  441. }
  442. $this->getWorksheet()->setDataValidation($this->getCoordinate(), $dataValidation);
  443. return $this->updateInCollection();
  444. }
  445. /**
  446. * Does this cell contain valid value?
  447. */
  448. public function hasValidValue(): bool
  449. {
  450. $validator = new DataValidator();
  451. return $validator->isValid($this);
  452. }
  453. /**
  454. * Does this cell contain a Hyperlink?
  455. */
  456. public function hasHyperlink(): bool
  457. {
  458. if (!isset($this->parent)) {
  459. throw new Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
  460. }
  461. return $this->getWorksheet()->hyperlinkExists($this->getCoordinate());
  462. }
  463. /**
  464. * Get Hyperlink.
  465. */
  466. public function getHyperlink(): Hyperlink
  467. {
  468. if (!isset($this->parent)) {
  469. throw new Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
  470. }
  471. return $this->getWorksheet()->getHyperlink($this->getCoordinate());
  472. }
  473. /**
  474. * Set Hyperlink.
  475. */
  476. public function setHyperlink(?Hyperlink $hyperlink = null): self
  477. {
  478. if (!isset($this->parent)) {
  479. throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
  480. }
  481. $this->getWorksheet()->setHyperlink($this->getCoordinate(), $hyperlink);
  482. return $this->updateInCollection();
  483. }
  484. /**
  485. * Get cell collection.
  486. *
  487. * @return ?Cells
  488. */
  489. public function getParent()
  490. {
  491. return $this->parent;
  492. }
  493. /**
  494. * Get parent worksheet.
  495. */
  496. public function getWorksheet(): Worksheet
  497. {
  498. $parent = $this->parent;
  499. if ($parent !== null) {
  500. $worksheet = $parent->getParent();
  501. } else {
  502. $worksheet = null;
  503. }
  504. if ($worksheet === null) {
  505. throw new Exception('Worksheet no longer exists');
  506. }
  507. return $worksheet;
  508. }
  509. public function getWorksheetOrNull(): ?Worksheet
  510. {
  511. $parent = $this->parent;
  512. if ($parent !== null) {
  513. $worksheet = $parent->getParent();
  514. } else {
  515. $worksheet = null;
  516. }
  517. return $worksheet;
  518. }
  519. /**
  520. * Is this cell in a merge range.
  521. */
  522. public function isInMergeRange(): bool
  523. {
  524. return (bool) $this->getMergeRange();
  525. }
  526. /**
  527. * Is this cell the master (top left cell) in a merge range (that holds the actual data value).
  528. */
  529. public function isMergeRangeValueCell(): bool
  530. {
  531. if ($mergeRange = $this->getMergeRange()) {
  532. $mergeRange = Coordinate::splitRange($mergeRange);
  533. [$startCell] = $mergeRange[0];
  534. return $this->getCoordinate() === $startCell;
  535. }
  536. return false;
  537. }
  538. /**
  539. * If this cell is in a merge range, then return the range.
  540. *
  541. * @return false|string
  542. */
  543. public function getMergeRange()
  544. {
  545. foreach ($this->getWorksheet()->getMergeCells() as $mergeRange) {
  546. if ($this->isInRange($mergeRange)) {
  547. return $mergeRange;
  548. }
  549. }
  550. return false;
  551. }
  552. /**
  553. * Get cell style.
  554. */
  555. public function getStyle(): Style
  556. {
  557. return $this->getWorksheet()->getStyle($this->getCoordinate());
  558. }
  559. /**
  560. * Get cell style.
  561. */
  562. public function getAppliedStyle(): Style
  563. {
  564. if ($this->getWorksheet()->conditionalStylesExists($this->getCoordinate()) === false) {
  565. return $this->getStyle();
  566. }
  567. $range = $this->getWorksheet()->getConditionalRange($this->getCoordinate());
  568. if ($range === null) {
  569. return $this->getStyle();
  570. }
  571. $matcher = new CellStyleAssessor($this, $range);
  572. return $matcher->matchConditions($this->getWorksheet()->getConditionalStyles($this->getCoordinate()));
  573. }
  574. /**
  575. * Re-bind parent.
  576. */
  577. public function rebindParent(Worksheet $parent): self
  578. {
  579. $this->parent = $parent->getCellCollection();
  580. return $this->updateInCollection();
  581. }
  582. /**
  583. * Is cell in a specific range?
  584. *
  585. * @param string $range Cell range (e.g. A1:A1)
  586. */
  587. public function isInRange(string $range): bool
  588. {
  589. [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($range);
  590. // Translate properties
  591. $myColumn = Coordinate::columnIndexFromString($this->getColumn());
  592. $myRow = $this->getRow();
  593. // Verify if cell is in range
  594. return ($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
  595. ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow);
  596. }
  597. /**
  598. * Compare 2 cells.
  599. *
  600. * @param Cell $a Cell a
  601. * @param Cell $b Cell b
  602. *
  603. * @return int Result of comparison (always -1 or 1, never zero!)
  604. */
  605. public static function compareCells(self $a, self $b): int
  606. {
  607. if ($a->getRow() < $b->getRow()) {
  608. return -1;
  609. } elseif ($a->getRow() > $b->getRow()) {
  610. return 1;
  611. } elseif (Coordinate::columnIndexFromString($a->getColumn()) < Coordinate::columnIndexFromString($b->getColumn())) {
  612. return -1;
  613. }
  614. return 1;
  615. }
  616. /**
  617. * Get value binder to use.
  618. */
  619. public static function getValueBinder(): IValueBinder
  620. {
  621. if (self::$valueBinder === null) {
  622. self::$valueBinder = new DefaultValueBinder();
  623. }
  624. return self::$valueBinder;
  625. }
  626. /**
  627. * Set value binder to use.
  628. */
  629. public static function setValueBinder(IValueBinder $binder): void
  630. {
  631. self::$valueBinder = $binder;
  632. }
  633. /**
  634. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  635. */
  636. public function __clone()
  637. {
  638. $vars = get_object_vars($this);
  639. foreach ($vars as $propertyName => $propertyValue) {
  640. if ((is_object($propertyValue)) && ($propertyName !== 'parent')) {
  641. $this->$propertyName = clone $propertyValue;
  642. } else {
  643. $this->$propertyName = $propertyValue;
  644. }
  645. }
  646. }
  647. /**
  648. * Get index to cellXf.
  649. */
  650. public function getXfIndex(): int
  651. {
  652. return $this->xfIndex;
  653. }
  654. /**
  655. * Set index to cellXf.
  656. */
  657. public function setXfIndex(int $indexValue): self
  658. {
  659. $this->xfIndex = $indexValue;
  660. return $this->updateInCollection();
  661. }
  662. /**
  663. * Set the formula attributes.
  664. *
  665. * @param mixed $attributes
  666. *
  667. * @return $this
  668. */
  669. public function setFormulaAttributes($attributes): self
  670. {
  671. $this->formulaAttributes = $attributes;
  672. return $this;
  673. }
  674. /**
  675. * Get the formula attributes.
  676. *
  677. * @return mixed
  678. */
  679. public function getFormulaAttributes()
  680. {
  681. return $this->formulaAttributes;
  682. }
  683. /**
  684. * Convert to string.
  685. *
  686. * @return string
  687. */
  688. public function __toString()
  689. {
  690. return (string) $this->getValue();
  691. }
  692. public function getIgnoredErrors(): IgnoredErrors
  693. {
  694. return $this->ignoredErrors;
  695. }
  696. }