Rename $pCell parameters
This commit is contained in:
parent
89edc5b267
commit
9d701d48ed
|
|
@ -3286,14 +3286,14 @@ class Calculation
|
||||||
* Calculate cell value (using formula from a cell ID)
|
* Calculate cell value (using formula from a cell ID)
|
||||||
* Retained for backward compatibility.
|
* Retained for backward compatibility.
|
||||||
*
|
*
|
||||||
* @param Cell $pCell Cell to calculate
|
* @param Cell $cell Cell to calculate
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function calculate(?Cell $pCell = null)
|
public function calculate(?Cell $cell = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->calculateCellValue($pCell);
|
return $this->calculateCellValue($cell);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -3302,14 +3302,14 @@ class Calculation
|
||||||
/**
|
/**
|
||||||
* Calculate the value of a cell formula.
|
* Calculate the value of a cell formula.
|
||||||
*
|
*
|
||||||
* @param Cell $pCell Cell to calculate
|
* @param Cell $cell Cell to calculate
|
||||||
* @param bool $resetLog Flag indicating whether the debug log should be reset or not
|
* @param bool $resetLog Flag indicating whether the debug log should be reset or not
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function calculateCellValue(?Cell $pCell = null, $resetLog = true)
|
public function calculateCellValue(?Cell $cell = null, $resetLog = true)
|
||||||
{
|
{
|
||||||
if ($pCell === null) {
|
if ($cell === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3326,12 +3326,12 @@ class Calculation
|
||||||
|
|
||||||
// Execute the calculation for the cell formula
|
// Execute the calculation for the cell formula
|
||||||
$this->cellStack[] = [
|
$this->cellStack[] = [
|
||||||
'sheet' => $pCell->getWorksheet()->getTitle(),
|
'sheet' => $cell->getWorksheet()->getTitle(),
|
||||||
'cell' => $pCell->getCoordinate(),
|
'cell' => $cell->getCoordinate(),
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = self::unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
|
$result = self::unwrapResult($this->_calculateFormulaValue($cell->getValue(), $cell->getCoordinate(), $cell));
|
||||||
$cellAddress = array_pop($this->cellStack);
|
$cellAddress = array_pop($this->cellStack);
|
||||||
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
|
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
@ -3367,7 +3367,7 @@ class Calculation
|
||||||
}
|
}
|
||||||
self::$returnArrayAsType = $returnArrayAsType;
|
self::$returnArrayAsType = $returnArrayAsType;
|
||||||
|
|
||||||
if ($result === null && $pCell->getWorksheet()->getSheetView()->getShowZeros()) {
|
if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) {
|
||||||
return 0;
|
return 0;
|
||||||
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
|
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
|
|
@ -3405,11 +3405,11 @@ class Calculation
|
||||||
*
|
*
|
||||||
* @param string $formula Formula to parse
|
* @param string $formula Formula to parse
|
||||||
* @param string $cellID Address of the cell to calculate
|
* @param string $cellID Address of the cell to calculate
|
||||||
* @param Cell $pCell Cell to calculate
|
* @param Cell $cell Cell to calculate
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function calculateFormula($formula, $cellID = null, ?Cell $pCell = null)
|
public function calculateFormula($formula, $cellID = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
// Initialise the logging settings
|
// Initialise the logging settings
|
||||||
$this->formulaError = null;
|
$this->formulaError = null;
|
||||||
|
|
@ -3417,9 +3417,9 @@ class Calculation
|
||||||
$this->cyclicReferenceStack->clear();
|
$this->cyclicReferenceStack->clear();
|
||||||
|
|
||||||
$resetCache = $this->getCalculationCacheEnabled();
|
$resetCache = $this->getCalculationCacheEnabled();
|
||||||
if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
|
if ($this->spreadsheet !== null && $cellID === null && $cell === null) {
|
||||||
$cellID = 'A1';
|
$cellID = 'A1';
|
||||||
$pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
|
$cell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
|
||||||
} else {
|
} else {
|
||||||
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
|
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
|
||||||
// But don't actually flush any cache
|
// But don't actually flush any cache
|
||||||
|
|
@ -3428,7 +3428,7 @@ class Calculation
|
||||||
|
|
||||||
// Execute the calculation
|
// Execute the calculation
|
||||||
try {
|
try {
|
||||||
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
|
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $cell));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -3477,16 +3477,16 @@ class Calculation
|
||||||
*
|
*
|
||||||
* @param string $formula The formula to parse and calculate
|
* @param string $formula The formula to parse and calculate
|
||||||
* @param string $cellID The ID (e.g. A3) of the cell that we are calculating
|
* @param string $cellID The ID (e.g. A3) of the cell that we are calculating
|
||||||
* @param Cell $pCell Cell to calculate
|
* @param Cell $cell Cell to calculate
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function _calculateFormulaValue($formula, $cellID = null, ?Cell $pCell = null)
|
public function _calculateFormulaValue($formula, $cellID = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
$cellValue = null;
|
$cellValue = null;
|
||||||
|
|
||||||
// Quote-Prefixed cell values cannot be formulae, but are treated as strings
|
// Quote-Prefixed cell values cannot be formulae, but are treated as strings
|
||||||
if ($pCell !== null && $pCell->getStyle()->getQuotePrefix() === true) {
|
if ($cell !== null && $cell->getStyle()->getQuotePrefix() === true) {
|
||||||
return self::wrapResult((string) $formula);
|
return self::wrapResult((string) $formula);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3505,7 +3505,7 @@ class Calculation
|
||||||
return self::wrapResult($formula);
|
return self::wrapResult($formula);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
|
$pCellParent = ($cell !== null) ? $cell->getWorksheet() : null;
|
||||||
$wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk";
|
$wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk";
|
||||||
$wsCellReference = $wsTitle . '!' . $cellID;
|
$wsCellReference = $wsTitle . '!' . $cellID;
|
||||||
|
|
||||||
|
|
@ -3538,7 +3538,7 @@ class Calculation
|
||||||
// Parse the formula onto the token stack and calculate the value
|
// Parse the formula onto the token stack and calculate the value
|
||||||
$this->cyclicReferenceStack->push($wsCellReference);
|
$this->cyclicReferenceStack->push($wsCellReference);
|
||||||
|
|
||||||
$cellValue = $this->processTokenStack($this->internalParseFormula($formula, $pCell), $cellID, $pCell);
|
$cellValue = $this->processTokenStack($this->internalParseFormula($formula, $cell), $cellID, $cell);
|
||||||
$this->cyclicReferenceStack->pop();
|
$this->cyclicReferenceStack->pop();
|
||||||
|
|
||||||
// Save to calculation cache
|
// Save to calculation cache
|
||||||
|
|
@ -3882,7 +3882,7 @@ class Calculation
|
||||||
*
|
*
|
||||||
* @return array<int, mixed>|false
|
* @return array<int, mixed>|false
|
||||||
*/
|
*/
|
||||||
private function internalParseFormula($formula, ?Cell $pCell = null)
|
private function internalParseFormula($formula, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
|
if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -3890,7 +3890,7 @@ class Calculation
|
||||||
|
|
||||||
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
|
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
|
||||||
// so we store the parent worksheet so that we can re-attach it when necessary
|
// so we store the parent worksheet so that we can re-attach it when necessary
|
||||||
$pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
|
$pCellParent = ($cell !== null) ? $cell->getWorksheet() : null;
|
||||||
|
|
||||||
$regexpMatchString = '/^(' . self::CALCULATION_REGEXP_FUNCTION .
|
$regexpMatchString = '/^(' . self::CALCULATION_REGEXP_FUNCTION .
|
||||||
'|' . self::CALCULATION_REGEXP_CELLREF .
|
'|' . self::CALCULATION_REGEXP_CELLREF .
|
||||||
|
|
@ -4384,7 +4384,7 @@ class Calculation
|
||||||
*
|
*
|
||||||
* @return array<int, mixed>|false
|
* @return array<int, mixed>|false
|
||||||
*/
|
*/
|
||||||
private function processTokenStack($tokens, $cellID = null, ?Cell $pCell = null)
|
private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($tokens == false) {
|
if ($tokens == false) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -4392,8 +4392,8 @@ class Calculation
|
||||||
|
|
||||||
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection),
|
// If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection),
|
||||||
// so we store the parent cell collection so that we can re-attach it when necessary
|
// so we store the parent cell collection so that we can re-attach it when necessary
|
||||||
$pCellWorksheet = ($pCell !== null) ? $pCell->getWorksheet() : null;
|
$pCellWorksheet = ($cell !== null) ? $cell->getWorksheet() : null;
|
||||||
$pCellParent = ($pCell !== null) ? $pCell->getParent() : null;
|
$pCellParent = ($cell !== null) ? $cell->getParent() : null;
|
||||||
$stack = new Stack();
|
$stack = new Stack();
|
||||||
|
|
||||||
// Stores branches that have been pruned
|
// Stores branches that have been pruned
|
||||||
|
|
@ -4527,20 +4527,20 @@ class Calculation
|
||||||
if (trim($sheet1, "'") === trim($sheet2, "'")) {
|
if (trim($sheet1, "'") === trim($sheet2, "'")) {
|
||||||
if ($operand1Data['reference'] === null) {
|
if ($operand1Data['reference'] === null) {
|
||||||
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
|
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
|
||||||
$operand1Data['reference'] = $pCell->getColumn() . $operand1Data['value'];
|
$operand1Data['reference'] = $cell->getColumn() . $operand1Data['value'];
|
||||||
} elseif (trim($operand1Data['reference']) == '') {
|
} elseif (trim($operand1Data['reference']) == '') {
|
||||||
$operand1Data['reference'] = $pCell->getCoordinate();
|
$operand1Data['reference'] = $cell->getCoordinate();
|
||||||
} else {
|
} else {
|
||||||
$operand1Data['reference'] = $operand1Data['value'] . $pCell->getRow();
|
$operand1Data['reference'] = $operand1Data['value'] . $cell->getRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($operand2Data['reference'] === null) {
|
if ($operand2Data['reference'] === null) {
|
||||||
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
|
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
|
||||||
$operand2Data['reference'] = $pCell->getColumn() . $operand2Data['value'];
|
$operand2Data['reference'] = $cell->getColumn() . $operand2Data['value'];
|
||||||
} elseif (trim($operand2Data['reference']) == '') {
|
} elseif (trim($operand2Data['reference']) == '') {
|
||||||
$operand2Data['reference'] = $pCell->getCoordinate();
|
$operand2Data['reference'] = $cell->getCoordinate();
|
||||||
} else {
|
} else {
|
||||||
$operand2Data['reference'] = $operand2Data['value'] . $pCell->getRow();
|
$operand2Data['reference'] = $operand2Data['value'] . $cell->getRow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4693,7 +4693,7 @@ class Calculation
|
||||||
$cellRef = null;
|
$cellRef = null;
|
||||||
|
|
||||||
if (isset($matches[8])) {
|
if (isset($matches[8])) {
|
||||||
if ($pCell === null) {
|
if ($cell === null) {
|
||||||
// We can't access the range, so return a REF error
|
// We can't access the range, so return a REF error
|
||||||
$cellValue = Functions::REF();
|
$cellValue = Functions::REF();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -4723,7 +4723,7 @@ class Calculation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($pCell === null) {
|
if ($cell === null) {
|
||||||
// We can't access the cell, so return a REF error
|
// We can't access the cell, so return a REF error
|
||||||
$cellValue = Functions::REF();
|
$cellValue = Functions::REF();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -4739,7 +4739,7 @@ class Calculation
|
||||||
$cellSheet = $this->spreadsheet->getSheetByName($matches[2]);
|
$cellSheet = $this->spreadsheet->getSheetByName($matches[2]);
|
||||||
if ($cellSheet && $cellSheet->cellExists($cellRef)) {
|
if ($cellSheet && $cellSheet->cellExists($cellRef)) {
|
||||||
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
|
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
|
||||||
$pCell->attach($pCellParent);
|
$cell->attach($pCellParent);
|
||||||
} else {
|
} else {
|
||||||
$cellRef = ($cellSheet !== null) ? "'{$matches[2]}'!{$cellRef}" : $cellRef;
|
$cellRef = ($cellSheet !== null) ? "'{$matches[2]}'!{$cellRef}" : $cellRef;
|
||||||
$cellValue = null;
|
$cellValue = null;
|
||||||
|
|
@ -4752,7 +4752,7 @@ class Calculation
|
||||||
$this->debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
|
$this->debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
|
||||||
if ($pCellParent->has($cellRef)) {
|
if ($pCellParent->has($cellRef)) {
|
||||||
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
|
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
|
||||||
$pCell->attach($pCellParent);
|
$cell->attach($pCellParent);
|
||||||
} else {
|
} else {
|
||||||
$cellValue = null;
|
$cellValue = null;
|
||||||
}
|
}
|
||||||
|
|
@ -4769,7 +4769,7 @@ class Calculation
|
||||||
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
|
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
|
||||||
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) {
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) {
|
||||||
if ($pCellParent) {
|
if ($pCellParent) {
|
||||||
$pCell->attach($pCellParent);
|
$cell->attach($pCellParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
$functionName = $matches[1];
|
$functionName = $matches[1];
|
||||||
|
|
@ -4844,7 +4844,7 @@ class Calculation
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the argument with the appropriate function call
|
// Process the argument with the appropriate function call
|
||||||
$args = $this->addCellReference($args, $passCellReference, $functionCall, $pCell);
|
$args = $this->addCellReference($args, $passCellReference, $functionCall, $cell);
|
||||||
|
|
||||||
if (!is_array($functionCall)) {
|
if (!is_array($functionCall)) {
|
||||||
foreach ($args as &$arg) {
|
foreach ($args as &$arg) {
|
||||||
|
|
@ -4880,7 +4880,7 @@ class Calculation
|
||||||
// if the token is a named range or formula, evaluate it and push the result onto the stack
|
// if the token is a named range or formula, evaluate it and push the result onto the stack
|
||||||
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/miu', $token, $matches)) {
|
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/miu', $token, $matches)) {
|
||||||
$definedName = $matches[6];
|
$definedName = $matches[6];
|
||||||
if ($pCell === null || $pCellWorksheet === null) {
|
if ($cell === null || $pCellWorksheet === null) {
|
||||||
return $this->raiseFormulaError("undefined name '$token'");
|
return $this->raiseFormulaError("undefined name '$token'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4890,7 +4890,7 @@ class Calculation
|
||||||
return $this->raiseFormulaError("undefined name '$definedName'");
|
return $this->raiseFormulaError("undefined name '$definedName'");
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->evaluateDefinedName($pCell, $namedRange, $pCellWorksheet, $stack);
|
$result = $this->evaluateDefinedName($cell, $namedRange, $pCellWorksheet, $stack);
|
||||||
if (isset($storeKey)) {
|
if (isset($storeKey)) {
|
||||||
$branchStore[$storeKey] = $result;
|
$branchStore[$storeKey] = $result;
|
||||||
}
|
}
|
||||||
|
|
@ -5454,7 +5454,7 @@ class Calculation
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function addCellReference(array $args, $passCellReference, $functionCall, ?Cell $pCell = null)
|
private function addCellReference(array $args, $passCellReference, $functionCall, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($passCellReference) {
|
if ($passCellReference) {
|
||||||
if (is_array($functionCall)) {
|
if (is_array($functionCall)) {
|
||||||
|
|
@ -5468,7 +5468,7 @@ class Calculation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$args[] = $pCell;
|
$args[] = $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
|
|
@ -5499,10 +5499,10 @@ class Calculation
|
||||||
/**
|
/**
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
private function evaluateDefinedName(Cell $pCell, DefinedName $namedRange, Worksheet $pCellWorksheet, Stack $stack)
|
private function evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksheet $cellWorksheet, Stack $stack)
|
||||||
{
|
{
|
||||||
$definedNameScope = $namedRange->getScope();
|
$definedNameScope = $namedRange->getScope();
|
||||||
if ($definedNameScope !== null && $definedNameScope !== $pCellWorksheet) {
|
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) {
|
||||||
// The defined name isn't in our current scope, so #REF
|
// The defined name isn't in our current scope, so #REF
|
||||||
$result = Functions::REF();
|
$result = Functions::REF();
|
||||||
$stack->push('Error', $result, $namedRange->getName());
|
$stack->push('Error', $result, $namedRange->getName());
|
||||||
|
|
@ -5520,16 +5520,16 @@ class Calculation
|
||||||
|
|
||||||
$this->debugLog->writeDebugLog("Defined Name is a {$definedNameType} with a value of {$definedNameValue}");
|
$this->debugLog->writeDebugLog("Defined Name is a {$definedNameType} with a value of {$definedNameValue}");
|
||||||
|
|
||||||
$recursiveCalculationCell = ($definedNameWorksheet !== null && $definedNameWorksheet !== $pCellWorksheet)
|
$recursiveCalculationCell = ($definedNameWorksheet !== null && $definedNameWorksheet !== $cellWorksheet)
|
||||||
? $definedNameWorksheet->getCell('A1')
|
? $definedNameWorksheet->getCell('A1')
|
||||||
: $pCell;
|
: $cell;
|
||||||
$recursiveCalculationCellAddress = $recursiveCalculationCell->getCoordinate();
|
$recursiveCalculationCellAddress = $recursiveCalculationCell->getCoordinate();
|
||||||
|
|
||||||
// Adjust relative references in ranges and formulae so that we execute the calculation for the correct rows and columns
|
// Adjust relative references in ranges and formulae so that we execute the calculation for the correct rows and columns
|
||||||
$definedNameValue = self::$referenceHelper->updateFormulaReferencesAnyWorksheet(
|
$definedNameValue = self::$referenceHelper->updateFormulaReferencesAnyWorksheet(
|
||||||
$definedNameValue,
|
$definedNameValue,
|
||||||
Coordinate::columnIndexFromString($pCell->getColumn()) - 1,
|
Coordinate::columnIndexFromString($cell->getColumn()) - 1,
|
||||||
$pCell->getRow() - 1
|
$cell->getRow() - 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->debugLog->writeDebugLog("Value adjusted for relative references is {$definedNameValue}");
|
$this->debugLog->writeDebugLog("Value adjusted for relative references is {$definedNameValue}");
|
||||||
|
|
|
||||||
|
|
@ -661,16 +661,16 @@ class Functions
|
||||||
* ISFORMULA.
|
* ISFORMULA.
|
||||||
*
|
*
|
||||||
* @param mixed $cellReference The cell to check
|
* @param mixed $cellReference The cell to check
|
||||||
* @param ?Cell $pCell The current cell (containing this formula)
|
* @param ?Cell $cell The current cell (containing this formula)
|
||||||
*
|
*
|
||||||
* @return bool|string
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public static function isFormula($cellReference = '', ?Cell $pCell = null)
|
public static function isFormula($cellReference = '', ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($pCell === null) {
|
if ($cell === null) {
|
||||||
return self::REF();
|
return self::REF();
|
||||||
}
|
}
|
||||||
$cellReference = self::expandDefinedName((string) $cellReference, $pCell);
|
$cellReference = self::expandDefinedName((string) $cellReference, $cell);
|
||||||
$cellReference = self::trimTrailingRange($cellReference);
|
$cellReference = self::trimTrailingRange($cellReference);
|
||||||
|
|
||||||
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
|
||||||
|
|
@ -679,15 +679,15 @@ class Functions
|
||||||
$worksheetName = str_replace("''", "'", trim($matches[2], "'"));
|
$worksheetName = str_replace("''", "'", trim($matches[2], "'"));
|
||||||
|
|
||||||
$worksheet = (!empty($worksheetName))
|
$worksheet = (!empty($worksheetName))
|
||||||
? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
||||||
: $pCell->getWorksheet();
|
: $cell->getWorksheet();
|
||||||
|
|
||||||
return $worksheet->getCell($cellReference)->isFormula();
|
return $worksheet->getCell($cellReference)->isFormula();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function expandDefinedName(string $pCoordinate, Cell $pCell): string
|
public static function expandDefinedName(string $pCoordinate, Cell $cell): string
|
||||||
{
|
{
|
||||||
$worksheet = $pCell->getWorksheet();
|
$worksheet = $cell->getWorksheet();
|
||||||
$spreadsheet = $worksheet->getParent();
|
$spreadsheet = $worksheet->getParent();
|
||||||
// Uppercase coordinate
|
// Uppercase coordinate
|
||||||
$pCoordinatex = strtoupper($pCoordinate);
|
$pCoordinatex = strtoupper($pCoordinate);
|
||||||
|
|
|
||||||
|
|
@ -158,18 +158,18 @@ class LookupRef
|
||||||
*
|
*
|
||||||
* @Deprecated 1.18.0
|
* @Deprecated 1.18.0
|
||||||
*
|
*
|
||||||
* @see LookupRef\Hyperlink::set()
|
|
||||||
* Use the set() method in the LookupRef\Hyperlink class instead
|
|
||||||
*
|
|
||||||
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
|
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
|
||||||
* @param mixed $displayName Expect string. Value to return when testValue is an error condition
|
* @param mixed $displayName Expect string. Value to return when testValue is an error condition
|
||||||
* @param Cell $pCell The cell to set the hyperlink in
|
* @param Cell $cell The cell to set the hyperlink in
|
||||||
*
|
*
|
||||||
* @return string The value of $displayName (or $linkURL if $displayName was blank)
|
* @return string The value of $displayName (or $linkURL if $displayName was blank)
|
||||||
|
*
|
||||||
|
*@see LookupRef\Hyperlink::set()
|
||||||
|
* Use the set() method in the LookupRef\Hyperlink class instead
|
||||||
*/
|
*/
|
||||||
public static function HYPERLINK($linkURL = '', $displayName = null, ?Cell $pCell = null)
|
public static function HYPERLINK($linkURL = '', $displayName = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
return LookupRef\Hyperlink::set($linkURL, $displayName, $pCell);
|
return LookupRef\Hyperlink::set($linkURL, $displayName, $cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -183,19 +183,19 @@ class LookupRef
|
||||||
*
|
*
|
||||||
* @Deprecated 1.18.0
|
* @Deprecated 1.18.0
|
||||||
*
|
*
|
||||||
* @see LookupRef\Indirect::INDIRECT()
|
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
|
||||||
|
* @param Cell $cell The current cell (containing this formula)
|
||||||
|
*
|
||||||
|
* @return array|string An array containing a cell or range of cells, or a string on error
|
||||||
|
*
|
||||||
|
*@see LookupRef\Indirect::INDIRECT()
|
||||||
* Use the INDIRECT() method in the LookupRef\Indirect class instead
|
* Use the INDIRECT() method in the LookupRef\Indirect class instead
|
||||||
*
|
*
|
||||||
* NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010
|
* NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010
|
||||||
*
|
|
||||||
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
|
|
||||||
* @param Cell $pCell The current cell (containing this formula)
|
|
||||||
*
|
|
||||||
* @return array|string An array containing a cell or range of cells, or a string on error
|
|
||||||
*/
|
*/
|
||||||
public static function INDIRECT($cellAddress, Cell $pCell)
|
public static function INDIRECT($cellAddress, Cell $cell)
|
||||||
{
|
{
|
||||||
return Indirect::INDIRECT($cellAddress, true, $pCell);
|
return Indirect::INDIRECT($cellAddress, true, $cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -233,9 +233,9 @@ class LookupRef
|
||||||
*
|
*
|
||||||
* @return array|string An array containing a cell or range of cells, or a string on error
|
* @return array|string An array containing a cell or range of cells, or a string on error
|
||||||
*/
|
*/
|
||||||
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $pCell = null)
|
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
return Offset::OFFSET($cellAddress, $rows, $columns, $height, $width, $pCell);
|
return Offset::OFFSET($cellAddress, $rows, $columns, $height, $width, $cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -401,16 +401,16 @@ class LookupRef
|
||||||
*
|
*
|
||||||
* @Deprecated 1.18.0
|
* @Deprecated 1.18.0
|
||||||
*
|
*
|
||||||
* @see LookupRef\Formula::text()
|
|
||||||
* Use the text() method in the LookupRef\Formula class instead
|
|
||||||
*
|
|
||||||
* @param mixed $cellReference The cell to check
|
* @param mixed $cellReference The cell to check
|
||||||
* @param Cell $pCell The current cell (containing this formula)
|
* @param Cell $cell The current cell (containing this formula)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
*@see LookupRef\Formula::text()
|
||||||
|
* Use the text() method in the LookupRef\Formula class instead
|
||||||
*/
|
*/
|
||||||
public static function FORMULATEXT($cellReference = '', ?Cell $pCell = null)
|
public static function FORMULATEXT($cellReference = '', ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
return LookupRef\Formula::text($cellReference, $pCell);
|
return LookupRef\Formula::text($cellReference, $cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,13 @@ class Formula
|
||||||
* FORMULATEXT.
|
* FORMULATEXT.
|
||||||
*
|
*
|
||||||
* @param mixed $cellReference The cell to check
|
* @param mixed $cellReference The cell to check
|
||||||
* @param Cell $pCell The current cell (containing this formula)
|
* @param Cell $cell The current cell (containing this formula)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function text($cellReference = '', ?Cell $pCell = null)
|
public static function text($cellReference = '', ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if ($pCell === null) {
|
if ($cell === null) {
|
||||||
return Functions::REF();
|
return Functions::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,8 +27,8 @@ class Formula
|
||||||
$cellReference = $matches[6] . $matches[7];
|
$cellReference = $matches[6] . $matches[7];
|
||||||
$worksheetName = trim($matches[3], "'");
|
$worksheetName = trim($matches[3], "'");
|
||||||
$worksheet = (!empty($worksheetName))
|
$worksheet = (!empty($worksheetName))
|
||||||
? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
|
||||||
: $pCell->getWorksheet();
|
: $cell->getWorksheet();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$worksheet === null ||
|
$worksheet === null ||
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class Helpers
|
||||||
return [$cellAddress1, $cellAddress2, $cellAddress];
|
return [$cellAddress1, $cellAddress2, $cellAddress];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function extractWorksheet(string $cellAddress, Cell $pCell): array
|
public static function extractWorksheet(string $cellAddress, Cell $cell): array
|
||||||
{
|
{
|
||||||
$sheetName = '';
|
$sheetName = '';
|
||||||
if (strpos($cellAddress, '!') !== false) {
|
if (strpos($cellAddress, '!') !== false) {
|
||||||
|
|
@ -66,8 +66,8 @@ class Helpers
|
||||||
}
|
}
|
||||||
|
|
||||||
$worksheet = ($sheetName !== '')
|
$worksheet = ($sheetName !== '')
|
||||||
? $pCell->getWorksheet()->getParent()->getSheetByName($sheetName)
|
? $cell->getWorksheet()->getParent()->getSheetByName($sheetName)
|
||||||
: $pCell->getWorksheet();
|
: $cell->getWorksheet();
|
||||||
|
|
||||||
return [$cellAddress, $worksheet, $sheetName];
|
return [$cellAddress, $worksheet, $sheetName];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,16 +15,16 @@ class Hyperlink
|
||||||
*
|
*
|
||||||
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
|
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
|
||||||
* @param mixed $displayName Expect string. Value to return when testValue is an error condition
|
* @param mixed $displayName Expect string. Value to return when testValue is an error condition
|
||||||
* @param Cell $pCell The cell to set the hyperlink in
|
* @param Cell $cell The cell to set the hyperlink in
|
||||||
*
|
*
|
||||||
* @return mixed The value of $displayName (or $linkURL if $displayName was blank)
|
* @return mixed The value of $displayName (or $linkURL if $displayName was blank)
|
||||||
*/
|
*/
|
||||||
public static function set($linkURL = '', $displayName = null, ?Cell $pCell = null)
|
public static function set($linkURL = '', $displayName = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
$linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL);
|
$linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL);
|
||||||
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
|
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
|
||||||
|
|
||||||
if ((!is_object($pCell)) || (trim($linkURL) == '')) {
|
if ((!is_object($cell)) || (trim($linkURL) == '')) {
|
||||||
return Functions::REF();
|
return Functions::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,8 +32,8 @@ class Hyperlink
|
||||||
$displayName = $linkURL;
|
$displayName = $linkURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pCell->getHyperlink()->setUrl($linkURL);
|
$cell->getHyperlink()->setUrl($linkURL);
|
||||||
$pCell->getHyperlink()->setTooltip($displayName);
|
$cell->getHyperlink()->setTooltip($displayName);
|
||||||
|
|
||||||
return $displayName;
|
return $displayName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,11 @@ class Indirect
|
||||||
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
|
* @param array|string $cellAddress $cellAddress The cell address of the current cell (containing this formula)
|
||||||
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1,
|
* @param mixed $a1fmt Expect bool Helpers::CELLADDRESS_USE_A1 or CELLADDRESS_USE_R1C1,
|
||||||
* but can be provided as numeric which is cast to bool
|
* but can be provided as numeric which is cast to bool
|
||||||
* @param Cell $pCell The current cell (containing this formula)
|
* @param Cell $cell The current cell (containing this formula)
|
||||||
*
|
*
|
||||||
* @return array|string An array containing a cell or range of cells, or a string on error
|
* @return array|string An array containing a cell or range of cells, or a string on error
|
||||||
*/
|
*/
|
||||||
public static function INDIRECT($cellAddress, $a1fmt, Cell $pCell)
|
public static function INDIRECT($cellAddress, $a1fmt, Cell $cell)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$a1 = self::a1Format($a1fmt);
|
$a1 = self::a1Format($a1fmt);
|
||||||
|
|
@ -69,9 +69,9 @@ class Indirect
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
[$cellAddress, $worksheet, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
|
[$cellAddress, $worksheet, $sheetName] = Helpers::extractWorksheet($cellAddress, $cell);
|
||||||
|
|
||||||
[$cellAddress1, $cellAddress2, $cellAddress] = Helpers::extractCellAddresses($cellAddress, $a1, $pCell->getWorkSheet(), $sheetName);
|
[$cellAddress1, $cellAddress2, $cellAddress] = Helpers::extractCellAddresses($cellAddress, $a1, $cell->getWorkSheet(), $sheetName);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||
|
(!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class Offset
|
||||||
*
|
*
|
||||||
* @return array|int|string An array containing a cell or range of cells, or a string on error
|
* @return array|int|string An array containing a cell or range of cells, or a string on error
|
||||||
*/
|
*/
|
||||||
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $pCell = null)
|
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
$rows = Functions::flattenSingleValue($rows);
|
$rows = Functions::flattenSingleValue($rows);
|
||||||
$columns = Functions::flattenSingleValue($columns);
|
$columns = Functions::flattenSingleValue($columns);
|
||||||
|
|
@ -51,11 +51,11 @@ class Offset
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_object($pCell)) {
|
if (!is_object($cell)) {
|
||||||
return Functions::REF();
|
return Functions::REF();
|
||||||
}
|
}
|
||||||
|
|
||||||
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $pCell);
|
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell);
|
||||||
|
|
||||||
$startCell = $endCell = $cellAddress;
|
$startCell = $endCell = $cellAddress;
|
||||||
if (strpos($cellAddress, ':')) {
|
if (strpos($cellAddress, ':')) {
|
||||||
|
|
@ -96,7 +96,7 @@ class Offset
|
||||||
->extractCellRange($cellAddress, $worksheet, false);
|
->extractCellRange($cellAddress, $worksheet, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function extractWorksheet($cellAddress, Cell $pCell): array
|
private static function extractWorksheet($cellAddress, Cell $cell): array
|
||||||
{
|
{
|
||||||
$sheetName = '';
|
$sheetName = '';
|
||||||
if (strpos($cellAddress, '!') !== false) {
|
if (strpos($cellAddress, '!') !== false) {
|
||||||
|
|
@ -105,8 +105,8 @@ class Offset
|
||||||
}
|
}
|
||||||
|
|
||||||
$worksheet = ($sheetName !== '')
|
$worksheet = ($sheetName !== '')
|
||||||
? $pCell->getWorksheet()->getParent()->getSheetByName($sheetName)
|
? $cell->getWorksheet()->getParent()->getSheetByName($sheetName)
|
||||||
: $pCell->getWorksheet();
|
: $cell->getWorksheet();
|
||||||
|
|
||||||
return [$cellAddress, $worksheet];
|
return [$cellAddress, $worksheet];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ class RowColumnInformation
|
||||||
return $cellAddress === null || (!is_array($cellAddress) && trim($cellAddress) === '');
|
return $cellAddress === null || (!is_array($cellAddress) && trim($cellAddress) === '');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function cellColumn(?Cell $pCell): int
|
private static function cellColumn(?Cell $cell): int
|
||||||
{
|
{
|
||||||
return ($pCell !== null) ? (int) Coordinate::columnIndexFromString($pCell->getColumn()) : 1;
|
return ($cell !== null) ? (int) Coordinate::columnIndexFromString($cell->getColumn()) : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,10 +42,10 @@ class RowColumnInformation
|
||||||
*
|
*
|
||||||
* @return int|int[]
|
* @return int|int[]
|
||||||
*/
|
*/
|
||||||
public static function COLUMN($cellAddress = null, ?Cell $pCell = null)
|
public static function COLUMN($cellAddress = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if (self::cellAddressNullOrWhitespace($cellAddress)) {
|
if (self::cellAddressNullOrWhitespace($cellAddress)) {
|
||||||
return self::cellColumn($pCell);
|
return self::cellColumn($cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($cellAddress)) {
|
if (is_array($cellAddress)) {
|
||||||
|
|
@ -55,13 +55,13 @@ class RowColumnInformation
|
||||||
return (int) Coordinate::columnIndexFromString($columnKey);
|
return (int) Coordinate::columnIndexFromString($columnKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::cellColumn($pCell);
|
return self::cellColumn($cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cellAddress = $cellAddress ?? '';
|
$cellAddress = $cellAddress ?? '';
|
||||||
if ($pCell != null) {
|
if ($cell != null) {
|
||||||
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
|
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $cell);
|
||||||
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
|
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $cell->getWorksheet(), $sheetName);
|
||||||
}
|
}
|
||||||
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
|
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
|
||||||
if (strpos($cellAddress, ':') !== false) {
|
if (strpos($cellAddress, ':') !== false) {
|
||||||
|
|
@ -113,9 +113,9 @@ class RowColumnInformation
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function cellRow(?Cell $pCell): int
|
private static function cellRow(?Cell $cell): int
|
||||||
{
|
{
|
||||||
return ($pCell !== null) ? $pCell->getRow() : 1;
|
return ($cell !== null) ? $cell->getRow() : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -135,10 +135,10 @@ class RowColumnInformation
|
||||||
*
|
*
|
||||||
* @return int|mixed[]|string
|
* @return int|mixed[]|string
|
||||||
*/
|
*/
|
||||||
public static function ROW($cellAddress = null, ?Cell $pCell = null)
|
public static function ROW($cellAddress = null, ?Cell $cell = null)
|
||||||
{
|
{
|
||||||
if (self::cellAddressNullOrWhitespace($cellAddress)) {
|
if (self::cellAddressNullOrWhitespace($cellAddress)) {
|
||||||
return self::cellRow($pCell);
|
return self::cellRow($cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($cellAddress)) {
|
if (is_array($cellAddress)) {
|
||||||
|
|
@ -148,13 +148,13 @@ class RowColumnInformation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::cellRow($pCell);
|
return self::cellRow($cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cellAddress = $cellAddress ?? '';
|
$cellAddress = $cellAddress ?? '';
|
||||||
if ($pCell !== null) {
|
if ($cell !== null) {
|
||||||
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
|
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $cell);
|
||||||
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
|
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $cell->getWorksheet(), $sheetName);
|
||||||
}
|
}
|
||||||
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
|
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
|
||||||
if (strpos($cellAddress, ':') !== false) {
|
if (strpos($cellAddress, ':') !== false) {
|
||||||
|
|
|
||||||
|
|
@ -18,24 +18,24 @@ class RichText implements IComparable
|
||||||
/**
|
/**
|
||||||
* Create a new RichText instance.
|
* Create a new RichText instance.
|
||||||
*
|
*
|
||||||
* @param Cell $pCell
|
* @param Cell $cell
|
||||||
*/
|
*/
|
||||||
public function __construct(?Cell $pCell = null)
|
public function __construct(?Cell $cell = null)
|
||||||
{
|
{
|
||||||
// Initialise variables
|
// Initialise variables
|
||||||
$this->richTextElements = [];
|
$this->richTextElements = [];
|
||||||
|
|
||||||
// Rich-Text string attached to cell?
|
// Rich-Text string attached to cell?
|
||||||
if ($pCell !== null) {
|
if ($cell !== null) {
|
||||||
// Add cell text and style
|
// Add cell text and style
|
||||||
if ($pCell->getValue() != '') {
|
if ($cell->getValue() != '') {
|
||||||
$objRun = new Run($pCell->getValue());
|
$objRun = new Run($cell->getValue());
|
||||||
$objRun->setFont(clone $pCell->getWorksheet()->getStyle($pCell->getCoordinate())->getFont());
|
$objRun->setFont(clone $cell->getWorksheet()->getStyle($cell->getCoordinate())->getFont());
|
||||||
$this->addText($objRun);
|
$this->addText($objRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set parent value
|
// Set parent value
|
||||||
$pCell->setValueExplicit($this, DataType::TYPE_STRING);
|
$cell->setValueExplicit($this, DataType::TYPE_STRING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -333,12 +333,12 @@ class Date
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isDateTime(Cell $pCell)
|
public static function isDateTime(Cell $cell)
|
||||||
{
|
{
|
||||||
return is_numeric($pCell->getCalculatedValue()) &&
|
return is_numeric($cell->getCalculatedValue()) &&
|
||||||
self::isDateTimeFormat(
|
self::isDateTimeFormat(
|
||||||
$pCell->getWorksheet()->getStyle(
|
$cell->getWorksheet()->getStyle(
|
||||||
$pCell->getCoordinate()
|
$cell->getCoordinate()
|
||||||
)->getNumberFormat()
|
)->getNumberFormat()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1415,17 +1415,17 @@ class Worksheet implements IComparable
|
||||||
/**
|
/**
|
||||||
* Get style for cell.
|
* Get style for cell.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate (or range) to get style for, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate (or range) to get style for, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return Style
|
* @return Style
|
||||||
*/
|
*/
|
||||||
public function getStyle($pCellCoordinate)
|
public function getStyle($cellCoordinate)
|
||||||
{
|
{
|
||||||
// set this sheet as active
|
// set this sheet as active
|
||||||
$this->parent->setActiveSheetIndex($this->parent->getIndex($this));
|
$this->parent->setActiveSheetIndex($this->parent->getIndex($this));
|
||||||
|
|
||||||
// set cell coordinate as active
|
// set cell coordinate as active
|
||||||
$this->setSelectedCells($pCellCoordinate);
|
$this->setSelectedCells($cellCoordinate);
|
||||||
|
|
||||||
return $this->parent->getCellXfSupervisor();
|
return $this->parent->getCellXfSupervisor();
|
||||||
}
|
}
|
||||||
|
|
@ -1524,22 +1524,22 @@ class Worksheet implements IComparable
|
||||||
*
|
*
|
||||||
* Please note that this will overwrite existing cell styles for cells in range!
|
* Please note that this will overwrite existing cell styles for cells in range!
|
||||||
*
|
*
|
||||||
* @param Style $pCellStyle Cell style to duplicate
|
* @param Style $style Cell style to duplicate
|
||||||
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
|
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function duplicateStyle(Style $pCellStyle, $pRange)
|
public function duplicateStyle(Style $style, $pRange)
|
||||||
{
|
{
|
||||||
// Add the style to the workbook if necessary
|
// Add the style to the workbook if necessary
|
||||||
$workbook = $this->parent;
|
$workbook = $this->parent;
|
||||||
if ($existingStyle = $this->parent->getCellXfByHashCode($pCellStyle->getHashCode())) {
|
if ($existingStyle = $this->parent->getCellXfByHashCode($style->getHashCode())) {
|
||||||
// there is already such cell Xf in our collection
|
// there is already such cell Xf in our collection
|
||||||
$xfIndex = $existingStyle->getIndex();
|
$xfIndex = $existingStyle->getIndex();
|
||||||
} else {
|
} else {
|
||||||
// we don't have such a cell Xf, need to add
|
// we don't have such a cell Xf, need to add
|
||||||
$workbook->addCellXf($pCellStyle);
|
$workbook->addCellXf($style);
|
||||||
$xfIndex = $pCellStyle->getIndex();
|
$xfIndex = $style->getIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate range outer borders
|
// Calculate range outer borders
|
||||||
|
|
@ -1567,21 +1567,21 @@ class Worksheet implements IComparable
|
||||||
*
|
*
|
||||||
* Please note that this will overwrite existing cell styles for cells in range!
|
* Please note that this will overwrite existing cell styles for cells in range!
|
||||||
*
|
*
|
||||||
* @param Conditional[] $pCellStyle Cell style to duplicate
|
* @param Conditional[] $styles Cell style to duplicate
|
||||||
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
|
* @param string $range Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function duplicateConditionalStyle(array $pCellStyle, $pRange = '')
|
public function duplicateConditionalStyle(array $styles, $range = '')
|
||||||
{
|
{
|
||||||
foreach ($pCellStyle as $cellStyle) {
|
foreach ($styles as $cellStyle) {
|
||||||
if (!($cellStyle instanceof Conditional)) {
|
if (!($cellStyle instanceof Conditional)) {
|
||||||
throw new Exception('Style is not a conditional style');
|
throw new Exception('Style is not a conditional style');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate range outer borders
|
// Calculate range outer borders
|
||||||
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($pRange . ':' . $pRange);
|
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($range . ':' . $range);
|
||||||
|
|
||||||
// Make sure we can loop upwards on rows and columns
|
// Make sure we can loop upwards on rows and columns
|
||||||
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
|
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
|
||||||
|
|
@ -1593,7 +1593,7 @@ class Worksheet implements IComparable
|
||||||
// Loop through cells and apply styles
|
// Loop through cells and apply styles
|
||||||
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
|
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
|
||||||
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
|
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
|
||||||
$this->setConditionalStyles(Coordinate::stringFromColumnIndex($col) . $row, $pCellStyle);
|
$this->setConditionalStyles(Coordinate::stringFromColumnIndex($col) . $row, $styles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2299,31 +2299,31 @@ class Worksheet implements IComparable
|
||||||
/**
|
/**
|
||||||
* Get comment for cell.
|
* Get comment for cell.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate to get comment for, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate to get comment for, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return Comment
|
* @return Comment
|
||||||
*/
|
*/
|
||||||
public function getComment($pCellCoordinate)
|
public function getComment($cellCoordinate)
|
||||||
{
|
{
|
||||||
// Uppercase coordinate
|
// Uppercase coordinate
|
||||||
$pCellCoordinate = strtoupper($pCellCoordinate);
|
$cellCoordinate = strtoupper($cellCoordinate);
|
||||||
|
|
||||||
if (Coordinate::coordinateIsRange($pCellCoordinate)) {
|
if (Coordinate::coordinateIsRange($cellCoordinate)) {
|
||||||
throw new Exception('Cell coordinate string can not be a range of cells.');
|
throw new Exception('Cell coordinate string can not be a range of cells.');
|
||||||
} elseif (strpos($pCellCoordinate, '$') !== false) {
|
} elseif (strpos($cellCoordinate, '$') !== false) {
|
||||||
throw new Exception('Cell coordinate string must not be absolute.');
|
throw new Exception('Cell coordinate string must not be absolute.');
|
||||||
} elseif ($pCellCoordinate == '') {
|
} elseif ($cellCoordinate == '') {
|
||||||
throw new Exception('Cell coordinate can not be zero-length string.');
|
throw new Exception('Cell coordinate can not be zero-length string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we already have a comment for this cell.
|
// Check if we already have a comment for this cell.
|
||||||
if (isset($this->comments[$pCellCoordinate])) {
|
if (isset($this->comments[$cellCoordinate])) {
|
||||||
return $this->comments[$pCellCoordinate];
|
return $this->comments[$cellCoordinate];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not, create a new comment.
|
// If not, create a new comment.
|
||||||
$newComment = new Comment();
|
$newComment = new Comment();
|
||||||
$this->comments[$pCellCoordinate] = $newComment;
|
$this->comments[$cellCoordinate] = $newComment;
|
||||||
|
|
||||||
return $newComment;
|
return $newComment;
|
||||||
}
|
}
|
||||||
|
|
@ -2777,36 +2777,36 @@ class Worksheet implements IComparable
|
||||||
/**
|
/**
|
||||||
* Get hyperlink.
|
* Get hyperlink.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate to get hyperlink for, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate to get hyperlink for, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return Hyperlink
|
* @return Hyperlink
|
||||||
*/
|
*/
|
||||||
public function getHyperlink($pCellCoordinate)
|
public function getHyperlink($cellCoordinate)
|
||||||
{
|
{
|
||||||
// return hyperlink if we already have one
|
// return hyperlink if we already have one
|
||||||
if (isset($this->hyperlinkCollection[$pCellCoordinate])) {
|
if (isset($this->hyperlinkCollection[$cellCoordinate])) {
|
||||||
return $this->hyperlinkCollection[$pCellCoordinate];
|
return $this->hyperlinkCollection[$cellCoordinate];
|
||||||
}
|
}
|
||||||
|
|
||||||
// else create hyperlink
|
// else create hyperlink
|
||||||
$this->hyperlinkCollection[$pCellCoordinate] = new Hyperlink();
|
$this->hyperlinkCollection[$cellCoordinate] = new Hyperlink();
|
||||||
|
|
||||||
return $this->hyperlinkCollection[$pCellCoordinate];
|
return $this->hyperlinkCollection[$cellCoordinate];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set hyperlink.
|
* Set hyperlink.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate to insert hyperlink, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate to insert hyperlink, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setHyperlink($pCellCoordinate, ?Hyperlink $pHyperlink = null)
|
public function setHyperlink($cellCoordinate, ?Hyperlink $pHyperlink = null)
|
||||||
{
|
{
|
||||||
if ($pHyperlink === null) {
|
if ($pHyperlink === null) {
|
||||||
unset($this->hyperlinkCollection[$pCellCoordinate]);
|
unset($this->hyperlinkCollection[$cellCoordinate]);
|
||||||
} else {
|
} else {
|
||||||
$this->hyperlinkCollection[$pCellCoordinate] = $pHyperlink;
|
$this->hyperlinkCollection[$cellCoordinate] = $pHyperlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -2837,36 +2837,36 @@ class Worksheet implements IComparable
|
||||||
/**
|
/**
|
||||||
* Get data validation.
|
* Get data validation.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate to get data validation for, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate to get data validation for, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return DataValidation
|
* @return DataValidation
|
||||||
*/
|
*/
|
||||||
public function getDataValidation($pCellCoordinate)
|
public function getDataValidation($cellCoordinate)
|
||||||
{
|
{
|
||||||
// return data validation if we already have one
|
// return data validation if we already have one
|
||||||
if (isset($this->dataValidationCollection[$pCellCoordinate])) {
|
if (isset($this->dataValidationCollection[$cellCoordinate])) {
|
||||||
return $this->dataValidationCollection[$pCellCoordinate];
|
return $this->dataValidationCollection[$cellCoordinate];
|
||||||
}
|
}
|
||||||
|
|
||||||
// else create data validation
|
// else create data validation
|
||||||
$this->dataValidationCollection[$pCellCoordinate] = new DataValidation();
|
$this->dataValidationCollection[$cellCoordinate] = new DataValidation();
|
||||||
|
|
||||||
return $this->dataValidationCollection[$pCellCoordinate];
|
return $this->dataValidationCollection[$cellCoordinate];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set data validation.
|
* Set data validation.
|
||||||
*
|
*
|
||||||
* @param string $pCellCoordinate Cell coordinate to insert data validation, eg: 'A1'
|
* @param string $cellCoordinate Cell coordinate to insert data validation, eg: 'A1'
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setDataValidation($pCellCoordinate, ?DataValidation $pDataValidation = null)
|
public function setDataValidation($cellCoordinate, ?DataValidation $pDataValidation = null)
|
||||||
{
|
{
|
||||||
if ($pDataValidation === null) {
|
if ($pDataValidation === null) {
|
||||||
unset($this->dataValidationCollection[$pCellCoordinate]);
|
unset($this->dataValidationCollection[$cellCoordinate]);
|
||||||
} else {
|
} else {
|
||||||
$this->dataValidationCollection[$pCellCoordinate] = $pDataValidation;
|
$this->dataValidationCollection[$cellCoordinate] = $pDataValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
||||||
|
|
@ -66,15 +66,15 @@ class Comments extends WriterPart
|
||||||
* Write comment to XML format.
|
* Write comment to XML format.
|
||||||
*
|
*
|
||||||
* @param XMLWriter $objWriter XML Writer
|
* @param XMLWriter $objWriter XML Writer
|
||||||
* @param string $pCellReference Cell reference
|
* @param string $cellReference Cell reference
|
||||||
* @param Comment $pComment Comment
|
* @param Comment $pComment Comment
|
||||||
* @param array $pAuthors Array of authors
|
* @param array $pAuthors Array of authors
|
||||||
*/
|
*/
|
||||||
private function writeComment(XMLWriter $objWriter, $pCellReference, Comment $pComment, array $pAuthors): void
|
private function writeComment(XMLWriter $objWriter, $cellReference, Comment $pComment, array $pAuthors): void
|
||||||
{
|
{
|
||||||
// comment
|
// comment
|
||||||
$objWriter->startElement('comment');
|
$objWriter->startElement('comment');
|
||||||
$objWriter->writeAttribute('ref', $pCellReference);
|
$objWriter->writeAttribute('ref', $cellReference);
|
||||||
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
|
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
|
||||||
|
|
||||||
// text
|
// text
|
||||||
|
|
@ -159,13 +159,13 @@ class Comments extends WriterPart
|
||||||
* Write VML comment to XML format.
|
* Write VML comment to XML format.
|
||||||
*
|
*
|
||||||
* @param XMLWriter $objWriter XML Writer
|
* @param XMLWriter $objWriter XML Writer
|
||||||
* @param string $pCellReference Cell reference, eg: 'A1'
|
* @param string $cellReference Cell reference, eg: 'A1'
|
||||||
* @param Comment $pComment Comment
|
* @param Comment $pComment Comment
|
||||||
*/
|
*/
|
||||||
private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment): void
|
private function writeVMLComment(XMLWriter $objWriter, $cellReference, Comment $pComment): void
|
||||||
{
|
{
|
||||||
// Metadata
|
// Metadata
|
||||||
[$column, $row] = Coordinate::indexesFromString($pCellReference);
|
[$column, $row] = Coordinate::indexesFromString($cellReference);
|
||||||
$id = 1024 + $column + $row;
|
$id = 1024 + $column + $row;
|
||||||
$id = substr($id, 0, 4);
|
$id = substr($id, 0, 4);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1242,9 +1242,9 @@ class Worksheet extends WriterPart
|
||||||
$objWriter->writeElement('v', $cellIsFormula ? $formulaerr : $cellValue);
|
$objWriter->writeElement('v', $cellIsFormula ? $formulaerr : $cellValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeCellFormula(XMLWriter $objWriter, string $cellValue, Cell $pCell): void
|
private function writeCellFormula(XMLWriter $objWriter, string $cellValue, Cell $cell): void
|
||||||
{
|
{
|
||||||
$calculatedValue = $this->getParentWriter()->getPreCalculateFormulas() ? $pCell->getCalculatedValue() : $cellValue;
|
$calculatedValue = $this->getParentWriter()->getPreCalculateFormulas() ? $cell->getCalculatedValue() : $cellValue;
|
||||||
if (is_string($calculatedValue)) {
|
if (is_string($calculatedValue)) {
|
||||||
if (\PhpOffice\PhpSpreadsheet\Calculation\Functions::isError($calculatedValue)) {
|
if (\PhpOffice\PhpSpreadsheet\Calculation\Functions::isError($calculatedValue)) {
|
||||||
$this->writeCellError($objWriter, 'e', $cellValue, $calculatedValue);
|
$this->writeCellError($objWriter, 'e', $cellValue, $calculatedValue);
|
||||||
|
|
@ -1285,15 +1285,15 @@ class Worksheet extends WriterPart
|
||||||
*
|
*
|
||||||
* @param XMLWriter $objWriter XML Writer
|
* @param XMLWriter $objWriter XML Writer
|
||||||
* @param PhpspreadsheetWorksheet $worksheet Worksheet
|
* @param PhpspreadsheetWorksheet $worksheet Worksheet
|
||||||
* @param string $pCellAddress Cell Address
|
* @param string $cellAddress Cell Address
|
||||||
* @param string[] $pFlippedStringTable String table (flipped), for faster index searching
|
* @param string[] $pFlippedStringTable String table (flipped), for faster index searching
|
||||||
*/
|
*/
|
||||||
private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $worksheet, string $pCellAddress, array $pFlippedStringTable): void
|
private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $worksheet, string $cellAddress, array $pFlippedStringTable): void
|
||||||
{
|
{
|
||||||
// Cell
|
// Cell
|
||||||
$pCell = $worksheet->getCell($pCellAddress);
|
$pCell = $worksheet->getCell($cellAddress);
|
||||||
$objWriter->startElement('c');
|
$objWriter->startElement('c');
|
||||||
$objWriter->writeAttribute('r', $pCellAddress);
|
$objWriter->writeAttribute('r', $cellAddress);
|
||||||
|
|
||||||
// Sheet styles
|
// Sheet styles
|
||||||
$xfi = $pCell->getXfIndex();
|
$xfi = $pCell->getXfIndex();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue