# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Formula.php

TablePress – Tables in WordPress made easy, version 3.4. 45 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Formula.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Formula.php
- Modified: 2025-04-29T05:06:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/LookupRef/Formula.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\LookupRef;

use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use TablePress\PhpOffice\PhpSpreadsheet\Cell\Cell;
use TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper;

class Formula
{
	/**
	 * FORMULATEXT.
	 *
	 * @param mixed $cellReference The cell to check
	 * @param ?Cell $cell The current cell (containing this formula)
	 */
	public static function text($cellReference = '', ?Cell $cell = null): string
	{
		if ($cell === null) {
			return ExcelError::REF();
		}

		$worksheet = null;
		$cellReference = StringHelper::convertToString($cellReference);
		if (1 === preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches)) {
			$cellReference = $matches[6] . $matches[7];
			$worksheetName = trim($matches[3], "'");
			$worksheet = (!empty($worksheetName))
				? $cell->getWorksheet()->getParentOrThrow()->getSheetByName($worksheetName)
				: $cell->getWorksheet();
		}

		if (
			$worksheet === null
			|| !$worksheet->cellExists($cellReference)
			|| !$worksheet->getCell($cellReference)->isFormula()
		) {
			return ExcelError::NA();
		}

		return $worksheet->getCell($cellReference)->getValueString();
	}
}

```
