Rename $pCell parameters

This commit is contained in:
Adrien Crivelli 2021-11-07 14:43:17 +09:00
parent 89edc5b267
commit 9d701d48ed
14 changed files with 182 additions and 182 deletions

View File

@ -3286,14 +3286,14 @@ class Calculation
* Calculate cell value (using formula from a cell ID)
* Retained for backward compatibility.
*
* @param Cell $pCell Cell to calculate
* @param Cell $cell Cell to calculate
*
* @return mixed
*/
public function calculate(?Cell $pCell = null)
public function calculate(?Cell $cell = null)
{
try {
return $this->calculateCellValue($pCell);
return $this->calculateCellValue($cell);
} catch (\Exception $e) {
throw new Exception($e->getMessage());
}
@ -3302,14 +3302,14 @@ class Calculation
/**
* 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
*
* @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;
}
@ -3326,12 +3326,12 @@ class Calculation
// Execute the calculation for the cell formula
$this->cellStack[] = [
'sheet' => $pCell->getWorksheet()->getTitle(),
'cell' => $pCell->getCoordinate(),
'sheet' => $cell->getWorksheet()->getTitle(),
'cell' => $cell->getCoordinate(),
];
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);
$this->spreadsheet->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
} catch (\Exception $e) {
@ -3367,7 +3367,7 @@ class Calculation
}
self::$returnArrayAsType = $returnArrayAsType;
if ($result === null && $pCell->getWorksheet()->getSheetView()->getShowZeros()) {
if ($result === null && $cell->getWorksheet()->getSheetView()->getShowZeros()) {
return 0;
} elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
return Functions::NAN();
@ -3405,11 +3405,11 @@ class Calculation
*
* @param string $formula Formula to parse
* @param string $cellID Address of the cell to calculate
* @param Cell $pCell Cell to calculate
* @param Cell $cell Cell to calculate
*
* @return mixed
*/
public function calculateFormula($formula, $cellID = null, ?Cell $pCell = null)
public function calculateFormula($formula, $cellID = null, ?Cell $cell = null)
{
// Initialise the logging settings
$this->formulaError = null;
@ -3417,9 +3417,9 @@ class Calculation
$this->cyclicReferenceStack->clear();
$resetCache = $this->getCalculationCacheEnabled();
if ($this->spreadsheet !== null && $cellID === null && $pCell === null) {
if ($this->spreadsheet !== null && $cellID === null && $cell === null) {
$cellID = 'A1';
$pCell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
$cell = $this->spreadsheet->getActiveSheet()->getCell($cellID);
} else {
// Disable calculation cacheing because it only applies to cell calculations, not straight formulae
// But don't actually flush any cache
@ -3428,7 +3428,7 @@ class Calculation
// Execute the calculation
try {
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
$result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $cell));
} catch (\Exception $e) {
throw new Exception($e->getMessage());
}
@ -3477,16 +3477,16 @@ class Calculation
*
* @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 Cell $pCell Cell to calculate
* @param Cell $cell Cell to calculate
*
* @return mixed
*/
public function _calculateFormulaValue($formula, $cellID = null, ?Cell $pCell = null)
public function _calculateFormulaValue($formula, $cellID = null, ?Cell $cell = null)
{
$cellValue = null;
// 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);
}
@ -3505,7 +3505,7 @@ class Calculation
return self::wrapResult($formula);
}
$pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
$pCellParent = ($cell !== null) ? $cell->getWorksheet() : null;
$wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk";
$wsCellReference = $wsTitle . '!' . $cellID;
@ -3538,7 +3538,7 @@ class Calculation
// Parse the formula onto the token stack and calculate the value
$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();
// Save to calculation cache
@ -3882,7 +3882,7 @@ class Calculation
*
* @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) {
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),
// 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 .
'|' . self::CALCULATION_REGEXP_CELLREF .
@ -4384,7 +4384,7 @@ class Calculation
*
* @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) {
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),
// so we store the parent cell collection so that we can re-attach it when necessary
$pCellWorksheet = ($pCell !== null) ? $pCell->getWorksheet() : null;
$pCellParent = ($pCell !== null) ? $pCell->getParent() : null;
$pCellWorksheet = ($cell !== null) ? $cell->getWorksheet() : null;
$pCellParent = ($cell !== null) ? $cell->getParent() : null;
$stack = new Stack();
// Stores branches that have been pruned
@ -4527,20 +4527,20 @@ class Calculation
if (trim($sheet1, "'") === trim($sheet2, "'")) {
if ($operand1Data['reference'] === null) {
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
$operand1Data['reference'] = $pCell->getColumn() . $operand1Data['value'];
$operand1Data['reference'] = $cell->getColumn() . $operand1Data['value'];
} elseif (trim($operand1Data['reference']) == '') {
$operand1Data['reference'] = $pCell->getCoordinate();
$operand1Data['reference'] = $cell->getCoordinate();
} else {
$operand1Data['reference'] = $operand1Data['value'] . $pCell->getRow();
$operand1Data['reference'] = $operand1Data['value'] . $cell->getRow();
}
}
if ($operand2Data['reference'] === null) {
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
$operand2Data['reference'] = $pCell->getColumn() . $operand2Data['value'];
$operand2Data['reference'] = $cell->getColumn() . $operand2Data['value'];
} elseif (trim($operand2Data['reference']) == '') {
$operand2Data['reference'] = $pCell->getCoordinate();
$operand2Data['reference'] = $cell->getCoordinate();
} else {
$operand2Data['reference'] = $operand2Data['value'] . $pCell->getRow();
$operand2Data['reference'] = $operand2Data['value'] . $cell->getRow();
}
}
@ -4693,7 +4693,7 @@ class Calculation
$cellRef = null;
if (isset($matches[8])) {
if ($pCell === null) {
if ($cell === null) {
// We can't access the range, so return a REF error
$cellValue = Functions::REF();
} else {
@ -4723,7 +4723,7 @@ class Calculation
}
}
} else {
if ($pCell === null) {
if ($cell === null) {
// We can't access the cell, so return a REF error
$cellValue = Functions::REF();
} else {
@ -4739,7 +4739,7 @@ class Calculation
$cellSheet = $this->spreadsheet->getSheetByName($matches[2]);
if ($cellSheet && $cellSheet->cellExists($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
$pCell->attach($pCellParent);
$cell->attach($pCellParent);
} else {
$cellRef = ($cellSheet !== null) ? "'{$matches[2]}'!{$cellRef}" : $cellRef;
$cellValue = null;
@ -4752,7 +4752,7 @@ class Calculation
$this->debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
if ($pCellParent->has($cellRef)) {
$cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
$pCell->attach($pCellParent);
$cell->attach($pCellParent);
} else {
$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
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) {
if ($pCellParent) {
$pCell->attach($pCellParent);
$cell->attach($pCellParent);
}
$functionName = $matches[1];
@ -4844,7 +4844,7 @@ class Calculation
}
// 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)) {
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
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '$/miu', $token, $matches)) {
$definedName = $matches[6];
if ($pCell === null || $pCellWorksheet === null) {
if ($cell === null || $pCellWorksheet === null) {
return $this->raiseFormulaError("undefined name '$token'");
}
@ -4890,7 +4890,7 @@ class Calculation
return $this->raiseFormulaError("undefined name '$definedName'");
}
$result = $this->evaluateDefinedName($pCell, $namedRange, $pCellWorksheet, $stack);
$result = $this->evaluateDefinedName($cell, $namedRange, $pCellWorksheet, $stack);
if (isset($storeKey)) {
$branchStore[$storeKey] = $result;
}
@ -5454,7 +5454,7 @@ class Calculation
*
* @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 (is_array($functionCall)) {
@ -5468,7 +5468,7 @@ class Calculation
}
}
$args[] = $pCell;
$args[] = $cell;
}
return $args;
@ -5499,10 +5499,10 @@ class Calculation
/**
* @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();
if ($definedNameScope !== null && $definedNameScope !== $pCellWorksheet) {
if ($definedNameScope !== null && $definedNameScope !== $cellWorksheet) {
// The defined name isn't in our current scope, so #REF
$result = Functions::REF();
$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}");
$recursiveCalculationCell = ($definedNameWorksheet !== null && $definedNameWorksheet !== $pCellWorksheet)
$recursiveCalculationCell = ($definedNameWorksheet !== null && $definedNameWorksheet !== $cellWorksheet)
? $definedNameWorksheet->getCell('A1')
: $pCell;
: $cell;
$recursiveCalculationCellAddress = $recursiveCalculationCell->getCoordinate();
// Adjust relative references in ranges and formulae so that we execute the calculation for the correct rows and columns
$definedNameValue = self::$referenceHelper->updateFormulaReferencesAnyWorksheet(
$definedNameValue,
Coordinate::columnIndexFromString($pCell->getColumn()) - 1,
$pCell->getRow() - 1
Coordinate::columnIndexFromString($cell->getColumn()) - 1,
$cell->getRow() - 1
);
$this->debugLog->writeDebugLog("Value adjusted for relative references is {$definedNameValue}");

View File

@ -661,16 +661,16 @@ class Functions
* ISFORMULA.
*
* @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
*/
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();
}
$cellReference = self::expandDefinedName((string) $cellReference, $pCell);
$cellReference = self::expandDefinedName((string) $cellReference, $cell);
$cellReference = self::trimTrailingRange($cellReference);
preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
@ -679,15 +679,15 @@ class Functions
$worksheetName = str_replace("''", "'", trim($matches[2], "'"));
$worksheet = (!empty($worksheetName))
? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
: $pCell->getWorksheet();
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
: $cell->getWorksheet();
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();
// Uppercase coordinate
$pCoordinatex = strtoupper($pCoordinate);

View File

@ -158,18 +158,18 @@ class LookupRef
*
* @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 $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)
*
*@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
*
* @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
*
* 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
*/
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
*
* @see LookupRef\Formula::text()
* Use the text() method in the LookupRef\Formula class instead
*
* @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
*
*@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);
}
}

View File

@ -12,13 +12,13 @@ class Formula
* FORMULATEXT.
*
* @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
*/
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();
}
@ -27,8 +27,8 @@ class Formula
$cellReference = $matches[6] . $matches[7];
$worksheetName = trim($matches[3], "'");
$worksheet = (!empty($worksheetName))
? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
: $pCell->getWorksheet();
? $cell->getWorksheet()->getParent()->getSheetByName($worksheetName)
: $cell->getWorksheet();
if (
$worksheet === null ||

View File

@ -57,7 +57,7 @@ class Helpers
return [$cellAddress1, $cellAddress2, $cellAddress];
}
public static function extractWorksheet(string $cellAddress, Cell $pCell): array
public static function extractWorksheet(string $cellAddress, Cell $cell): array
{
$sheetName = '';
if (strpos($cellAddress, '!') !== false) {
@ -66,8 +66,8 @@ class Helpers
}
$worksheet = ($sheetName !== '')
? $pCell->getWorksheet()->getParent()->getSheetByName($sheetName)
: $pCell->getWorksheet();
? $cell->getWorksheet()->getParent()->getSheetByName($sheetName)
: $cell->getWorksheet();
return [$cellAddress, $worksheet, $sheetName];
}

View File

@ -15,16 +15,16 @@ class Hyperlink
*
* @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 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)
*/
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);
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
if ((!is_object($pCell)) || (trim($linkURL) == '')) {
if ((!is_object($cell)) || (trim($linkURL) == '')) {
return Functions::REF();
}
@ -32,8 +32,8 @@ class Hyperlink
$displayName = $linkURL;
}
$pCell->getHyperlink()->setUrl($linkURL);
$pCell->getHyperlink()->setTooltip($displayName);
$cell->getHyperlink()->setUrl($linkURL);
$cell->getHyperlink()->setTooltip($displayName);
return $displayName;
}

View File

@ -56,11 +56,11 @@ class Indirect
* @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,
* 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
*/
public static function INDIRECT($cellAddress, $a1fmt, Cell $pCell)
public static function INDIRECT($cellAddress, $a1fmt, Cell $cell)
{
try {
$a1 = self::a1Format($a1fmt);
@ -69,9 +69,9 @@ class Indirect
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 (
(!preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellAddress1, $matches)) ||

View File

@ -40,7 +40,7 @@ class Offset
*
* @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);
$columns = Functions::flattenSingleValue($columns);
@ -51,11 +51,11 @@ class Offset
return 0;
}
if (!is_object($pCell)) {
if (!is_object($cell)) {
return Functions::REF();
}
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $pCell);
[$cellAddress, $worksheet] = self::extractWorksheet($cellAddress, $cell);
$startCell = $endCell = $cellAddress;
if (strpos($cellAddress, ':')) {
@ -96,7 +96,7 @@ class Offset
->extractCellRange($cellAddress, $worksheet, false);
}
private static function extractWorksheet($cellAddress, Cell $pCell): array
private static function extractWorksheet($cellAddress, Cell $cell): array
{
$sheetName = '';
if (strpos($cellAddress, '!') !== false) {
@ -105,8 +105,8 @@ class Offset
}
$worksheet = ($sheetName !== '')
? $pCell->getWorksheet()->getParent()->getSheetByName($sheetName)
: $pCell->getWorksheet();
? $cell->getWorksheet()->getParent()->getSheetByName($sheetName)
: $cell->getWorksheet();
return [$cellAddress, $worksheet];
}

View File

@ -20,9 +20,9 @@ class RowColumnInformation
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[]
*/
public static function COLUMN($cellAddress = null, ?Cell $pCell = null)
public static function COLUMN($cellAddress = null, ?Cell $cell = null)
{
if (self::cellAddressNullOrWhitespace($cellAddress)) {
return self::cellColumn($pCell);
return self::cellColumn($cell);
}
if (is_array($cellAddress)) {
@ -55,13 +55,13 @@ class RowColumnInformation
return (int) Coordinate::columnIndexFromString($columnKey);
}
return self::cellColumn($pCell);
return self::cellColumn($cell);
}
$cellAddress = $cellAddress ?? '';
if ($pCell != null) {
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
if ($cell != null) {
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $cell);
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $cell->getWorksheet(), $sheetName);
}
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
if (strpos($cellAddress, ':') !== false) {
@ -113,9 +113,9 @@ class RowColumnInformation
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
*/
public static function ROW($cellAddress = null, ?Cell $pCell = null)
public static function ROW($cellAddress = null, ?Cell $cell = null)
{
if (self::cellAddressNullOrWhitespace($cellAddress)) {
return self::cellRow($pCell);
return self::cellRow($cell);
}
if (is_array($cellAddress)) {
@ -148,13 +148,13 @@ class RowColumnInformation
}
}
return self::cellRow($pCell);
return self::cellRow($cell);
}
$cellAddress = $cellAddress ?? '';
if ($pCell !== null) {
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $pCell);
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $pCell->getWorksheet(), $sheetName);
if ($cell !== null) {
[,, $sheetName] = Helpers::extractWorksheet($cellAddress, $cell);
[,, $cellAddress] = Helpers::extractCellAddresses($cellAddress, true, $cell->getWorksheet(), $sheetName);
}
[, $cellAddress] = Worksheet::extractSheetTitle($cellAddress, true);
if (strpos($cellAddress, ':') !== false) {

View File

@ -18,24 +18,24 @@ class RichText implements IComparable
/**
* 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
$this->richTextElements = [];
// Rich-Text string attached to cell?
if ($pCell !== null) {
if ($cell !== null) {
// Add cell text and style
if ($pCell->getValue() != '') {
$objRun = new Run($pCell->getValue());
$objRun->setFont(clone $pCell->getWorksheet()->getStyle($pCell->getCoordinate())->getFont());
if ($cell->getValue() != '') {
$objRun = new Run($cell->getValue());
$objRun->setFont(clone $cell->getWorksheet()->getStyle($cell->getCoordinate())->getFont());
$this->addText($objRun);
}
// Set parent value
$pCell->setValueExplicit($this, DataType::TYPE_STRING);
$cell->setValueExplicit($this, DataType::TYPE_STRING);
}
}

View File

@ -333,12 +333,12 @@ class Date
*
* @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(
$pCell->getWorksheet()->getStyle(
$pCell->getCoordinate()
$cell->getWorksheet()->getStyle(
$cell->getCoordinate()
)->getNumberFormat()
);
}

View File

@ -1415,17 +1415,17 @@ class Worksheet implements IComparable
/**
* 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
*/
public function getStyle($pCellCoordinate)
public function getStyle($cellCoordinate)
{
// set this sheet as active
$this->parent->setActiveSheetIndex($this->parent->getIndex($this));
// set cell coordinate as active
$this->setSelectedCells($pCellCoordinate);
$this->setSelectedCells($cellCoordinate);
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!
*
* @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")
*
* @return $this
*/
public function duplicateStyle(Style $pCellStyle, $pRange)
public function duplicateStyle(Style $style, $pRange)
{
// Add the style to the workbook if necessary
$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
$xfIndex = $existingStyle->getIndex();
} else {
// we don't have such a cell Xf, need to add
$workbook->addCellXf($pCellStyle);
$xfIndex = $pCellStyle->getIndex();
$workbook->addCellXf($style);
$xfIndex = $style->getIndex();
}
// 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!
*
* @param Conditional[] $pCellStyle Cell style to duplicate
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
* @param Conditional[] $styles Cell style to duplicate
* @param string $range Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
*
* @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)) {
throw new Exception('Style is not a conditional style');
}
}
// 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
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
@ -1593,7 +1593,7 @@ class Worksheet implements IComparable
// Loop through cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
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.
*
* @param string $pCellCoordinate Cell coordinate to get comment for, eg: 'A1'
* @param string $cellCoordinate Cell coordinate to get comment for, eg: 'A1'
*
* @return Comment
*/
public function getComment($pCellCoordinate)
public function getComment($cellCoordinate)
{
// 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.');
} elseif (strpos($pCellCoordinate, '$') !== false) {
} elseif (strpos($cellCoordinate, '$') !== false) {
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.');
}
// Check if we already have a comment for this cell.
if (isset($this->comments[$pCellCoordinate])) {
return $this->comments[$pCellCoordinate];
if (isset($this->comments[$cellCoordinate])) {
return $this->comments[$cellCoordinate];
}
// If not, create a new comment.
$newComment = new Comment();
$this->comments[$pCellCoordinate] = $newComment;
$this->comments[$cellCoordinate] = $newComment;
return $newComment;
}
@ -2777,36 +2777,36 @@ class Worksheet implements IComparable
/**
* 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
*/
public function getHyperlink($pCellCoordinate)
public function getHyperlink($cellCoordinate)
{
// return hyperlink if we already have one
if (isset($this->hyperlinkCollection[$pCellCoordinate])) {
return $this->hyperlinkCollection[$pCellCoordinate];
if (isset($this->hyperlinkCollection[$cellCoordinate])) {
return $this->hyperlinkCollection[$cellCoordinate];
}
// else create hyperlink
$this->hyperlinkCollection[$pCellCoordinate] = new Hyperlink();
$this->hyperlinkCollection[$cellCoordinate] = new Hyperlink();
return $this->hyperlinkCollection[$pCellCoordinate];
return $this->hyperlinkCollection[$cellCoordinate];
}
/**
* Set hyperlink.
*
* @param string $pCellCoordinate Cell coordinate to insert hyperlink, eg: 'A1'
* @param string $cellCoordinate Cell coordinate to insert hyperlink, eg: 'A1'
*
* @return $this
*/
public function setHyperlink($pCellCoordinate, ?Hyperlink $pHyperlink = null)
public function setHyperlink($cellCoordinate, ?Hyperlink $pHyperlink = null)
{
if ($pHyperlink === null) {
unset($this->hyperlinkCollection[$pCellCoordinate]);
unset($this->hyperlinkCollection[$cellCoordinate]);
} else {
$this->hyperlinkCollection[$pCellCoordinate] = $pHyperlink;
$this->hyperlinkCollection[$cellCoordinate] = $pHyperlink;
}
return $this;
@ -2837,36 +2837,36 @@ class Worksheet implements IComparable
/**
* 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
*/
public function getDataValidation($pCellCoordinate)
public function getDataValidation($cellCoordinate)
{
// return data validation if we already have one
if (isset($this->dataValidationCollection[$pCellCoordinate])) {
return $this->dataValidationCollection[$pCellCoordinate];
if (isset($this->dataValidationCollection[$cellCoordinate])) {
return $this->dataValidationCollection[$cellCoordinate];
}
// 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.
*
* @param string $pCellCoordinate Cell coordinate to insert data validation, eg: 'A1'
* @param string $cellCoordinate Cell coordinate to insert data validation, eg: 'A1'
*
* @return $this
*/
public function setDataValidation($pCellCoordinate, ?DataValidation $pDataValidation = null)
public function setDataValidation($cellCoordinate, ?DataValidation $pDataValidation = null)
{
if ($pDataValidation === null) {
unset($this->dataValidationCollection[$pCellCoordinate]);
unset($this->dataValidationCollection[$cellCoordinate]);
} else {
$this->dataValidationCollection[$pCellCoordinate] = $pDataValidation;
$this->dataValidationCollection[$cellCoordinate] = $pDataValidation;
}
return $this;

View File

@ -66,15 +66,15 @@ class Comments extends WriterPart
* Write comment to XML format.
*
* @param XMLWriter $objWriter XML Writer
* @param string $pCellReference Cell reference
* @param string $cellReference Cell reference
* @param Comment $pComment Comment
* @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
$objWriter->startElement('comment');
$objWriter->writeAttribute('ref', $pCellReference);
$objWriter->writeAttribute('ref', $cellReference);
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
// text
@ -159,13 +159,13 @@ class Comments extends WriterPart
* Write VML comment to XML format.
*
* @param XMLWriter $objWriter XML Writer
* @param string $pCellReference Cell reference, eg: 'A1'
* @param string $cellReference Cell reference, eg: 'A1'
* @param Comment $pComment Comment
*/
private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment): void
private function writeVMLComment(XMLWriter $objWriter, $cellReference, Comment $pComment): void
{
// Metadata
[$column, $row] = Coordinate::indexesFromString($pCellReference);
[$column, $row] = Coordinate::indexesFromString($cellReference);
$id = 1024 + $column + $row;
$id = substr($id, 0, 4);

View File

@ -1242,9 +1242,9 @@ class Worksheet extends WriterPart
$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 (\PhpOffice\PhpSpreadsheet\Calculation\Functions::isError($calculatedValue)) {
$this->writeCellError($objWriter, 'e', $cellValue, $calculatedValue);
@ -1285,15 +1285,15 @@ class Worksheet extends WriterPart
*
* @param XMLWriter $objWriter XML Writer
* @param PhpspreadsheetWorksheet $worksheet Worksheet
* @param string $pCellAddress Cell Address
* @param string $cellAddress Cell Address
* @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
$pCell = $worksheet->getCell($pCellAddress);
$pCell = $worksheet->getCell($cellAddress);
$objWriter->startElement('c');
$objWriter->writeAttribute('r', $pCellAddress);
$objWriter->writeAttribute('r', $cellAddress);
// Sheet styles
$xfi = $pCell->getXfIndex();