From af3918cac89935a86d357c144470d0d991433615 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Tue, 3 Nov 2020 17:45:12 +0100 Subject: [PATCH] Sane argument names in the Reference Helper, Settings and Spreadsheet classes --- src/PhpSpreadsheet/ReferenceHelper.php | 450 ++++++++++++------------- src/PhpSpreadsheet/Settings.php | 8 +- src/PhpSpreadsheet/Spreadsheet.php | 238 ++++++------- 3 files changed, 349 insertions(+), 347 deletions(-) diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 13f7cf71..09b88b25 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -119,26 +119,26 @@ class ReferenceHelper * * @param string $cellAddress Address of the cell we're testing * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfCols Number of columns to insert/delete (negative values indicate deletion) * * @return bool */ - private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols) + private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfCols) { [$cellColumn, $cellRow] = Coordinate::coordinateFromString($cellAddress); $cellColumnIndex = Coordinate::columnIndexFromString($cellColumn); // Is cell within the range of rows/columns if we're deleting if ( - $pNumRows < 0 && - ($cellRow >= ($beforeRow + $pNumRows)) && + $numberOfRows < 0 && + ($cellRow >= ($beforeRow + $numberOfRows)) && ($cellRow < $beforeRow) ) { return true; } elseif ( - $pNumCols < 0 && - ($cellColumnIndex >= ($beforeColumnIndex + $pNumCols)) && + $numberOfCols < 0 && + ($cellColumnIndex >= ($beforeColumnIndex + $numberOfCols)) && ($cellColumnIndex < $beforeColumnIndex) ) { return true; @@ -150,30 +150,30 @@ class ReferenceHelper /** * Update page breaks when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustPageBreaks(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustPageBreaks(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aBreaks = $pSheet->getBreaks(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aBreaks = $worksheet->getBreaks(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aBreaks, ['self', 'cellReverseSort']) : uksort($aBreaks, ['self', 'cellSort']); foreach ($aBreaks as $key => $value) { - if (self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { + if (self::cellAddressInDeleteRange($key, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfColumns)) { // If we're deleting, then clear any defined breaks that are within the range // of rows/columns that we're deleting - $pSheet->setBreak($key, Worksheet::BREAK_NONE); + $worksheet->setBreak($key, Worksheet::BREAK_NONE); } else { // Otherwise update any affected breaks by inserting a new break at the appropriate point // and removing the old affected break - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->setBreak($newReference, $value) + $worksheet->setBreak($newReference, $value) ->setBreak($key, Worksheet::BREAK_NONE); } } @@ -183,51 +183,51 @@ class ReferenceHelper /** * Update cell comments when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aComments = $pSheet->getComments(); + $aComments = $worksheet->getComments(); $aNewComments = []; // the new array of all comments foreach ($aComments as $key => &$value) { // Any comments inside a deleted range will be ignored - if (!self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { + if (!self::cellAddressInDeleteRange($key, $beforeRow, $numberOfRows, $beforeColumnIndex, $numberOfColumns)) { // Otherwise build a new array of comments indexed by the adjusted cell reference - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); $aNewComments[$newReference] = $value; } } // Replace the comments array with the new set of comments - $pSheet->setComments($aNewComments); + $worksheet->setComments($aNewComments); } /** * Update hyperlinks when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aHyperlinkCollection = $pSheet->getHyperlinkCollection(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aHyperlinkCollection = $worksheet->getHyperlinkCollection(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aHyperlinkCollection, ['self', 'cellReverseSort']) : uksort($aHyperlinkCollection, ['self', 'cellSort']); foreach ($aHyperlinkCollection as $key => $value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->setHyperlink($newReference, $value); - $pSheet->setHyperlink($key, null); + $worksheet->setHyperlink($newReference, $value); + $worksheet->setHyperlink($key, null); } } } @@ -242,7 +242,7 @@ class ReferenceHelper * @param int $beforeRow Number of the row we're inserting/deleting before * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustDataValidations(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void { $aDataValidationCollection = $pSheet->getDataValidationCollection(); ($pNumCols > 0 || $pNumRows > 0) ? @@ -260,44 +260,44 @@ class ReferenceHelper /** * Update merged cells when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustMergeCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aMergeCells = $pSheet->getMergeCells(); + $aMergeCells = $worksheet->getMergeCells(); $aNewMergeCells = []; // the new array of all merge cells foreach ($aMergeCells as $key => &$value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); $aNewMergeCells[$newReference] = $newReference; } - $pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array + $worksheet->setMergeCells($aNewMergeCells); // replace the merge cells array } /** * Update protected cells when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustProtectedCells(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aProtectedCells = $pSheet->getProtectedCells(); - ($pNumCols > 0 || $pNumRows > 0) ? + $aProtectedCells = $worksheet->getProtectedCells(); + ($numberOfColumns > 0 || $numberOfRows > 0) ? uksort($aProtectedCells, ['self', 'cellReverseSort']) : uksort($aProtectedCells, ['self', 'cellSort']); foreach ($aProtectedCells as $key => $value) { - $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($key, $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($key != $newReference) { - $pSheet->protectCells($newReference, $value, true); - $pSheet->unprotectCells($key); + $worksheet->protectCells($newReference, $value, true); + $worksheet->unprotectCells($key); } } } @@ -305,54 +305,54 @@ class ReferenceHelper /** * Update column dimensions when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustColumnDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true); + $aColumnDimensions = array_reverse($worksheet->getColumnDimensions(), true); if (!empty($aColumnDimensions)) { foreach ($aColumnDimensions as $objColumnDimension) { - $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $beforeCellAddress, $numberOfColumns, $numberOfRows); [$newReference] = Coordinate::coordinateFromString($newReference); if ($objColumnDimension->getColumnIndex() != $newReference) { $objColumnDimension->setColumnIndex($newReference); } } - $pSheet->refreshColumnDimensions(); + $worksheet->refreshColumnDimensions(); } } /** * Update row dimensions when inserting/deleting rows/columns. * - * @param Worksheet $pSheet The worksheet that we're editing - * @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') + * @param Worksheet $worksheet The worksheet that we're editing + * @param string $beforeCellAddress Insert/Delete before this cell address (e.g. 'A1') * @param int $beforeColumnIndex Index number of the column we're inserting/deleting before - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) * @param int $beforeRow Number of the row we're inserting/deleting before - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) */ - protected function adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void + protected function adjustRowDimensions(Worksheet $worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows): void { - $aRowDimensions = array_reverse($pSheet->getRowDimensions(), true); + $aRowDimensions = array_reverse($worksheet->getRowDimensions(), true); if (!empty($aRowDimensions)) { foreach ($aRowDimensions as $objRowDimension) { - $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $beforeCellAddress, $numberOfColumns, $numberOfRows); [, $newReference] = Coordinate::coordinateFromString($newReference); if ($objRowDimension->getRowIndex() != $newReference) { $objRowDimension->setRowIndex($newReference); } } - $pSheet->refreshRowDimensions(); + $worksheet->refreshRowDimensions(); - $copyDimension = $pSheet->getRowDimension($beforeRow - 1); - for ($i = $beforeRow; $i <= $beforeRow - 1 + $pNumRows; ++$i) { - $newDimension = $pSheet->getRowDimension($i); + $copyDimension = $worksheet->getRowDimension($beforeRow - 1); + for ($i = $beforeRow; $i <= $beforeRow - 1 + $numberOfRows; ++$i) { + $newDimension = $worksheet->getRowDimension($i); $newDimension->setRowHeight($copyDimension->getRowHeight()); $newDimension->setVisible($copyDimension->getVisible()); $newDimension->setOutlineLevel($copyDimension->getOutlineLevel()); @@ -364,47 +364,47 @@ class ReferenceHelper /** * Insert a new column or row, updating all possible related data. * - * @param string $pBefore Insert before this cell address (e.g. 'A1') - * @param int $pNumCols Number of columns to insert/delete (negative values indicate deletion) - * @param int $pNumRows Number of rows to insert/delete (negative values indicate deletion) - * @param Worksheet $pSheet The worksheet that we're editing + * @param string $beforeCellAddress Insert before this cell address (e.g. 'A1') + * @param int $numberOfColumns Number of columns to insert/delete (negative values indicate deletion) + * @param int $numberOfRows Number of rows to insert/delete (negative values indicate deletion) + * @param Worksheet $worksheet The worksheet that we're editing */ - public function insertNewBefore($pBefore, $pNumCols, $pNumRows, Worksheet $pSheet): void + public function insertNewBefore($beforeCellAddress, $numberOfColumns, $numberOfRows, Worksheet $worksheet): void { - $remove = ($pNumCols < 0 || $pNumRows < 0); - $allCoordinates = $pSheet->getCoordinates(); + $remove = ($numberOfColumns < 0 || $numberOfRows < 0); + $allCoordinates = $worksheet->getCoordinates(); // Get coordinate of $pBefore - [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($pBefore); + [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($beforeCellAddress); $beforeColumnIndex = Coordinate::columnIndexFromString($beforeColumn); // Clear cells if we are removing columns or rows - $highestColumn = $pSheet->getHighestColumn(); - $highestRow = $pSheet->getHighestRow(); + $highestColumn = $worksheet->getHighestColumn(); + $highestRow = $worksheet->getHighestRow(); // 1. Clear column strips if we are removing columns - if ($pNumCols < 0 && $beforeColumnIndex - 2 + $pNumCols > 0) { + if ($numberOfColumns < 0 && $beforeColumnIndex - 2 + $numberOfColumns > 0) { for ($i = 1; $i <= $highestRow - 1; ++$i) { - for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 2; ++$j) { + for ($j = $beforeColumnIndex - 1 + $numberOfColumns; $j <= $beforeColumnIndex - 2; ++$j) { $coordinate = Coordinate::stringFromColumnIndex($j + 1) . $i; - $pSheet->removeConditionalStyles($coordinate); - if ($pSheet->cellExists($coordinate)) { - $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); - $pSheet->getCell($coordinate)->setXfIndex(0); + $worksheet->removeConditionalStyles($coordinate); + if ($worksheet->cellExists($coordinate)) { + $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setXfIndex(0); } } } } // 2. Clear row strips if we are removing rows - if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) { + if ($numberOfRows < 0 && $beforeRow - 1 + $numberOfRows > 0) { for ($i = $beforeColumnIndex - 1; $i <= Coordinate::columnIndexFromString($highestColumn) - 1; ++$i) { - for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) { + for ($j = $beforeRow + $numberOfRows; $j <= $beforeRow - 1; ++$j) { $coordinate = Coordinate::stringFromColumnIndex($i + 1) . $j; - $pSheet->removeConditionalStyles($coordinate); - if ($pSheet->cellExists($coordinate)) { - $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); - $pSheet->getCell($coordinate)->setXfIndex(0); + $worksheet->removeConditionalStyles($coordinate); + if ($worksheet->cellExists($coordinate)) { + $worksheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); + $worksheet->getCell($coordinate)->setXfIndex(0); } } } @@ -416,85 +416,85 @@ class ReferenceHelper $allCoordinates = array_reverse($allCoordinates); } while ($coordinate = array_pop($allCoordinates)) { - $cell = $pSheet->getCell($coordinate); + $cell = $worksheet->getCell($coordinate); $cellIndex = Coordinate::columnIndexFromString($cell->getColumn()); - if ($cellIndex - 1 + $pNumCols < 0) { + if ($cellIndex - 1 + $numberOfColumns < 0) { continue; } // New coordinate - $newCoordinate = Coordinate::stringFromColumnIndex($cellIndex + $pNumCols) . ($cell->getRow() + $pNumRows); + $newCoordinate = Coordinate::stringFromColumnIndex($cellIndex + $numberOfColumns) . ($cell->getRow() + $numberOfRows); // Should the cell be updated? Move value and cellXf index from one cell to another. if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) { // Update cell styles - $pSheet->getCell($newCoordinate)->setXfIndex($cell->getXfIndex()); + $worksheet->getCell($newCoordinate)->setXfIndex($cell->getXfIndex()); // Insert this cell at its new location if ($cell->getDataType() == DataType::TYPE_FORMULA) { // Formula should be adjusted - $pSheet->getCell($newCoordinate) - ->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); + $worksheet->getCell($newCoordinate) + ->setValue($this->updateFormulaReferences($cell->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows, $worksheet->getTitle())); } else { // Formula should not be adjusted - $pSheet->getCell($newCoordinate)->setValue($cell->getValue()); + $worksheet->getCell($newCoordinate)->setValue($cell->getValue()); } // Clear the original cell - $pSheet->getCellCollection()->delete($coordinate); + $worksheet->getCellCollection()->delete($coordinate); } else { /* We don't need to update styles for rows/columns before our insertion position, but we do still need to adjust any formulae in those cells */ if ($cell->getDataType() == DataType::TYPE_FORMULA) { // Formula should be adjusted - $cell->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); + $cell->setValue($this->updateFormulaReferences($cell->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows, $worksheet->getTitle())); } } } // Duplicate styles for the newly inserted cells - $highestColumn = $pSheet->getHighestColumn(); - $highestRow = $pSheet->getHighestRow(); + $highestColumn = $worksheet->getHighestColumn(); + $highestRow = $worksheet->getHighestRow(); - if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) { + if ($numberOfColumns > 0 && $beforeColumnIndex - 2 > 0) { for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) { // Style $coordinate = Coordinate::stringFromColumnIndex($beforeColumnIndex - 1) . $i; - if ($pSheet->cellExists($coordinate)) { - $xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); - $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? - $pSheet->getConditionalStyles($coordinate) : false; - for ($j = $beforeColumnIndex; $j <= $beforeColumnIndex - 1 + $pNumCols; ++$j) { - $pSheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex); + if ($worksheet->cellExists($coordinate)) { + $xfIndex = $worksheet->getCell($coordinate)->getXfIndex(); + $conditionalStyles = $worksheet->conditionalStylesExists($coordinate) ? + $worksheet->getConditionalStyles($coordinate) : false; + for ($j = $beforeColumnIndex; $j <= $beforeColumnIndex - 1 + $numberOfColumns; ++$j) { + $worksheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex); if ($conditionalStyles) { $cloned = []; foreach ($conditionalStyles as $conditionalStyle) { $cloned[] = clone $conditionalStyle; } - $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($j) . $i, $cloned); + $worksheet->setConditionalStyles(Coordinate::stringFromColumnIndex($j) . $i, $cloned); } } } } } - if ($pNumRows > 0 && $beforeRow - 1 > 0) { + if ($numberOfRows > 0 && $beforeRow - 1 > 0) { for ($i = $beforeColumnIndex; $i <= Coordinate::columnIndexFromString($highestColumn); ++$i) { // Style $coordinate = Coordinate::stringFromColumnIndex($i) . ($beforeRow - 1); - if ($pSheet->cellExists($coordinate)) { - $xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); - $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? - $pSheet->getConditionalStyles($coordinate) : false; - for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) { - $pSheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); + if ($worksheet->cellExists($coordinate)) { + $xfIndex = $worksheet->getCell($coordinate)->getXfIndex(); + $conditionalStyles = $worksheet->conditionalStylesExists($coordinate) ? + $worksheet->getConditionalStyles($coordinate) : false; + for ($j = $beforeRow; $j <= $beforeRow - 1 + $numberOfRows; ++$j) { + $worksheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); if ($conditionalStyles) { $cloned = []; foreach ($conditionalStyles as $conditionalStyle) { $cloned[] = clone $conditionalStyle; } - $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($i) . $j, $cloned); + $worksheet->setConditionalStyles(Coordinate::stringFromColumnIndex($i) . $j, $cloned); } } } @@ -502,47 +502,47 @@ class ReferenceHelper } // Update worksheet: column dimensions - $this->adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustColumnDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: row dimensions - $this->adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustRowDimensions($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: page breaks - $this->adjustPageBreaks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustPageBreaks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: comments - $this->adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustComments($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: hyperlinks - $this->adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustHyperlinks($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: data validations - $this->adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustDataValidations($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: merge cells - $this->adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustMergeCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: protected cells - $this->adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); + $this->adjustProtectedCells($worksheet, $beforeCellAddress, $beforeColumnIndex, $numberOfColumns, $beforeRow, $numberOfRows); // Update worksheet: autofilter - $autoFilter = $pSheet->getAutoFilter(); + $autoFilter = $worksheet->getAutoFilter(); $autoFilterRange = $autoFilter->getRange(); if (!empty($autoFilterRange)) { - if ($pNumCols != 0) { + if ($numberOfColumns != 0) { $autoFilterColumns = $autoFilter->getColumns(); if (count($autoFilterColumns) > 0) { $column = ''; $row = 0; - sscanf($pBefore, '%[A-Z]%d', $column, $row); + sscanf($beforeCellAddress, '%[A-Z]%d', $column, $row); $columnIndex = Coordinate::columnIndexFromString($column); [$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($autoFilterRange); if ($columnIndex <= $rangeEnd[0]) { - if ($pNumCols < 0) { + if ($numberOfColumns < 0) { // If we're actually deleting any columns that fall within the autofilter range, // then we delete any rules for those columns - $deleteColumn = $columnIndex + $pNumCols - 1; - $deleteCount = abs($pNumCols); + $deleteColumn = $columnIndex + $numberOfColumns - 1; + $deleteCount = abs($numberOfColumns); for ($i = 1; $i <= $deleteCount; ++$i) { if (isset($autoFilterColumns[Coordinate::stringFromColumnIndex($deleteColumn + 1)])) { $autoFilter->clearColumn(Coordinate::stringFromColumnIndex($deleteColumn + 1)); @@ -553,10 +553,10 @@ class ReferenceHelper $startCol = ($columnIndex > $rangeStart[0]) ? $columnIndex : $rangeStart[0]; // Shuffle columns in autofilter range - if ($pNumCols > 0) { + if ($numberOfColumns > 0) { $startColRef = $startCol; $endColRef = $rangeEnd[0]; - $toColRef = $rangeEnd[0] + $pNumCols; + $toColRef = $rangeEnd[0] + $numberOfColumns; do { $autoFilter->shiftColumn(Coordinate::stringFromColumnIndex($endColRef), Coordinate::stringFromColumnIndex($toColRef)); @@ -566,7 +566,7 @@ class ReferenceHelper } else { // For delete, we shuffle from beginning to end to avoid overwriting $startColID = Coordinate::stringFromColumnIndex($startCol); - $toColID = Coordinate::stringFromColumnIndex($startCol + $pNumCols); + $toColID = Coordinate::stringFromColumnIndex($startCol + $numberOfColumns); $endColID = Coordinate::stringFromColumnIndex($rangeEnd[0] + 1); do { $autoFilter->shiftColumn($startColID, $toColID); @@ -577,62 +577,62 @@ class ReferenceHelper } } } - $pSheet->setAutoFilter($this->updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows)); + $worksheet->setAutoFilter($this->updateCellReference($autoFilterRange, $beforeCellAddress, $numberOfColumns, $numberOfRows)); } // Update worksheet: freeze pane - if ($pSheet->getFreezePane()) { - $splitCell = $pSheet->getFreezePane(); - $topLeftCell = $pSheet->getTopLeftCell(); + if ($worksheet->getFreezePane()) { + $splitCell = $worksheet->getFreezePane(); + $topLeftCell = $worksheet->getTopLeftCell(); - $splitCell = $this->updateCellReference($splitCell, $pBefore, $pNumCols, $pNumRows); - $topLeftCell = $this->updateCellReference($topLeftCell, $pBefore, $pNumCols, $pNumRows); + $splitCell = $this->updateCellReference($splitCell, $beforeCellAddress, $numberOfColumns, $numberOfRows); + $topLeftCell = $this->updateCellReference($topLeftCell, $beforeCellAddress, $numberOfColumns, $numberOfRows); - $pSheet->freezePane($splitCell, $topLeftCell); + $worksheet->freezePane($splitCell, $topLeftCell); } // Page setup - if ($pSheet->getPageSetup()->isPrintAreaSet()) { - $pSheet->getPageSetup()->setPrintArea($this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows)); + if ($worksheet->getPageSetup()->isPrintAreaSet()) { + $worksheet->getPageSetup()->setPrintArea($this->updateCellReference($worksheet->getPageSetup()->getPrintArea(), $beforeCellAddress, $numberOfColumns, $numberOfRows)); } // Update worksheet: drawings - $aDrawings = $pSheet->getDrawingCollection(); + $aDrawings = $worksheet->getDrawingCollection(); foreach ($aDrawings as $objDrawing) { - $newReference = $this->updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows); + $newReference = $this->updateCellReference($objDrawing->getCoordinates(), $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($objDrawing->getCoordinates() != $newReference) { $objDrawing->setCoordinates($newReference); } } // Update workbook: define names - if (count($pSheet->getParent()->getDefinedNames()) > 0) { - foreach ($pSheet->getParent()->getDefinedNames() as $definedName) { - if ($definedName->getWorksheet()->getHashCode() === $pSheet->getHashCode()) { - $definedName->setValue($this->updateCellReference($definedName->getValue(), $pBefore, $pNumCols, $pNumRows)); + if (count($worksheet->getParent()->getDefinedNames()) > 0) { + foreach ($worksheet->getParent()->getDefinedNames() as $definedName) { + if ($definedName->getWorksheet()->getHashCode() === $worksheet->getHashCode()) { + $definedName->setValue($this->updateCellReference($definedName->getValue(), $beforeCellAddress, $numberOfColumns, $numberOfRows)); } } } // Garbage collect - $pSheet->garbageCollect(); + $worksheet->garbageCollect(); } /** * Update references within formulas. * - * @param string $pFormula Formula to update - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to insert - * @param int $pNumRows Number of rows to insert - * @param string $sheetName Worksheet name/title + * @param string $formula Formula to update + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to insert + * @param int $numberOfRows Number of rows to insert + * @param string $worksheetName Worksheet name/title * * @return string Updated formula */ - public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, $sheetName = '') + public function updateFormulaReferences($formula = '', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0, $worksheetName = '') { // Update cell references in the formula - $formulaBlocks = explode('"', $pFormula); + $formulaBlocks = explode('"', $formula); $i = false; foreach ($formulaBlocks as &$formulaBlock) { // Ignore blocks that were enclosed in quotes (alternating entries in the $formulaBlocks array after the explode) @@ -645,11 +645,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = substr($this->updateCellReference('$A' . $match[3], $pBefore, $pNumCols, $pNumRows), 2); - $modified4 = substr($this->updateCellReference('$A' . $match[4], $pBefore, $pNumCols, $pNumRows), 2); + $modified3 = substr($this->updateCellReference('$A' . $match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows), 2); + $modified4 = substr($this->updateCellReference('$A' . $match[4], $beforeCellAddress, $numberOfColumns, $numberOfRows), 2); if ($match[3] . ':' . $match[4] !== $modified3 . ':' . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more @@ -670,11 +670,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = substr($this->updateCellReference($match[3] . '$1', $pBefore, $pNumCols, $pNumRows), 0, -2); - $modified4 = substr($this->updateCellReference($match[4] . '$1', $pBefore, $pNumCols, $pNumRows), 0, -2); + $modified3 = substr($this->updateCellReference($match[3] . '$1', $beforeCellAddress, $numberOfColumns, $numberOfRows), 0, -2); + $modified4 = substr($this->updateCellReference($match[4] . '$1', $beforeCellAddress, $numberOfColumns, $numberOfRows), 0, -2); if ($match[3] . ':' . $match[4] !== $modified3 . ':' . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more @@ -695,11 +695,11 @@ class ReferenceHelper foreach ($matches as $match) { $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3] . ':' . $match[4]; - $modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); - $modified4 = $this->updateCellReference($match[4], $pBefore, $pNumCols, $pNumRows); + $modified3 = $this->updateCellReference($match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows); + $modified4 = $this->updateCellReference($match[4], $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($match[3] . $match[4] !== $modified3 . $modified4) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3 . ':' . $modified4; [$column, $row] = Coordinate::coordinateFromString($match[3]); @@ -723,9 +723,9 @@ class ReferenceHelper $fromString = ($match[2] > '') ? $match[2] . '!' : ''; $fromString .= $match[3]; - $modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); + $modified3 = $this->updateCellReference($match[3], $beforeCellAddress, $numberOfColumns, $numberOfRows); if ($match[3] !== $modified3) { - if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { + if (($match[2] == '') || (trim($match[2], "'") == $worksheetName)) { $toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString .= $modified3; [$column, $row] = Coordinate::coordinateFromString($match[3]); @@ -742,7 +742,7 @@ class ReferenceHelper } } if ($adjustCount > 0) { - if ($pNumCols > 0 || $pNumRows > 0) { + if ($numberOfColumns > 0 || $numberOfRows > 0) { krsort($cellTokens); krsort($newCellTokens); } else { @@ -762,22 +762,22 @@ class ReferenceHelper /** * Update all cell references within a formula, irrespective of worksheet. */ - public function updateFormulaReferencesAnyWorksheet(string $formula = '', int $insertColumns = 0, int $insertRows = 0): string + public function updateFormulaReferencesAnyWorksheet(string $formula = '', int $numberOfColumns = 0, int $numberOfRows = 0): string { - $formula = $this->updateCellReferencesAllWorksheets($formula, $insertColumns, $insertRows); + $formula = $this->updateCellReferencesAllWorksheets($formula, $numberOfColumns, $numberOfRows); - if ($insertColumns !== 0) { - $formula = $this->updateColumnRangesAllWorksheets($formula, $insertColumns); + if ($numberOfColumns !== 0) { + $formula = $this->updateColumnRangesAllWorksheets($formula, $numberOfColumns); } - if ($insertRows !== 0) { - $formula = $this->updateRowRangesAllWorksheets($formula, $insertRows); + if ($numberOfRows !== 0) { + $formula = $this->updateRowRangesAllWorksheets($formula, $numberOfRows); } return $formula; } - private function updateCellReferencesAllWorksheets(string $formula, int $insertColumns, int $insertRows): string + private function updateCellReferencesAllWorksheets(string $formula, int $numberOfColumns, int $numberOfRows): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_CELLREF_RELATIVE . '/mui', @@ -804,11 +804,11 @@ class ReferenceHelper $row = $rows[$splitCount][0]; if (!empty($column) && $column[0] !== '$') { - $column = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($column) + $insertColumns); + $column = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($column) + $numberOfColumns); $formula = substr($formula, 0, $columnOffset) . $column . substr($formula, $columnOffset + $columnLength); } if (!empty($row) && $row[0] !== '$') { - $row += $insertRows; + $row += $numberOfRows; $formula = substr($formula, 0, $rowOffset) . $row . substr($formula, $rowOffset + $rowLength); } } @@ -816,7 +816,7 @@ class ReferenceHelper return $formula; } - private function updateColumnRangesAllWorksheets(string $formula, int $insertColumns): string + private function updateColumnRangesAllWorksheets(string $formula, int $numberOfColumns): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_COLUMNRANGE_RELATIVE . '/mui', @@ -843,11 +843,11 @@ class ReferenceHelper $toColumn = $toColumns[$splitCount][0]; if (!empty($fromColumn) && $fromColumn[0] !== '$') { - $fromColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($fromColumn) + $insertColumns); + $fromColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($fromColumn) + $numberOfColumns); $formula = substr($formula, 0, $fromColumnOffset) . $fromColumn . substr($formula, $fromColumnOffset + $fromColumnLength); } if (!empty($toColumn) && $toColumn[0] !== '$') { - $toColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($toColumn) + $insertColumns); + $toColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($toColumn) + $numberOfColumns); $formula = substr($formula, 0, $toColumnOffset) . $toColumn . substr($formula, $toColumnOffset + $toColumnLength); } } @@ -855,7 +855,7 @@ class ReferenceHelper return $formula; } - private function updateRowRangesAllWorksheets(string $formula, int $insertRows): string + private function updateRowRangesAllWorksheets(string $formula, int $numberOfRows): string { $splitCount = preg_match_all( '/' . Calculation::CALCULATION_REGEXP_ROWRANGE_RELATIVE . '/mui', @@ -882,11 +882,11 @@ class ReferenceHelper $toRow = $toRows[$splitCount][0]; if (!empty($fromRow) && $fromRow[0] !== '$') { - $fromRow += $insertRows; + $fromRow += $numberOfRows; $formula = substr($formula, 0, $fromRowOffset) . $fromRow . substr($formula, $fromRowOffset + $fromRowLength); } if (!empty($toRow) && $toRow[0] !== '$') { - $toRow += $insertRows; + $toRow += $numberOfRows; $formula = substr($formula, 0, $toRowOffset) . $toRow . substr($formula, $toRowOffset + $toRowLength); } } @@ -897,29 +897,29 @@ class ReferenceHelper /** * Update cell reference. * - * @param string $pCellRange Cell range - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellReference Cell address or range of addresses + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell range */ - public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + public function updateCellReference($cellReference = 'A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { // Is it in another worksheet? Will not have to update anything. - if (strpos($pCellRange, '!') !== false) { - return $pCellRange; + if (strpos($cellReference, '!') !== false) { + return $cellReference; // Is it a range or a single cell? - } elseif (!Coordinate::coordinateIsRange($pCellRange)) { + } elseif (!Coordinate::coordinateIsRange($cellReference)) { // Single cell - return $this->updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows); - } elseif (Coordinate::coordinateIsRange($pCellRange)) { + return $this->updateSingleCellReference($cellReference, $beforeCellAddress, $numberOfColumns, $numberOfRows); + } elseif (Coordinate::coordinateIsRange($cellReference)) { // Range - return $this->updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows); + return $this->updateCellRange($cellReference, $beforeCellAddress, $numberOfColumns, $numberOfRows); } // Return original - return $pCellRange; + return $cellReference; } /** @@ -953,33 +953,33 @@ class ReferenceHelper /** * Update cell range. * - * @param string $pCellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell range */ - private function updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + private function updateCellRange($cellRange = 'A1:A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { - if (!Coordinate::coordinateIsRange($pCellRange)) { + if (!Coordinate::coordinateIsRange($cellRange)) { throw new Exception('Only cell ranges may be passed to this method.'); } // Update range - $range = Coordinate::splitRange($pCellRange); + $range = Coordinate::splitRange($cellRange); $ic = count($range); for ($i = 0; $i < $ic; ++$i) { $jc = count($range[$i]); for ($j = 0; $j < $jc; ++$j) { if (ctype_alpha($range[$i][$j])) { - $r = Coordinate::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $pBefore, $pNumCols, $pNumRows)); + $r = Coordinate::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $beforeCellAddress, $numberOfColumns, $numberOfRows)); $range[$i][$j] = $r[0]; } elseif (ctype_digit($range[$i][$j])) { - $r = Coordinate::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $pBefore, $pNumCols, $pNumRows)); + $r = Coordinate::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $beforeCellAddress, $numberOfColumns, $numberOfRows)); $range[$i][$j] = $r[1]; } else { - $range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); + $range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $beforeCellAddress, $numberOfColumns, $numberOfRows); } } } @@ -991,24 +991,24 @@ class ReferenceHelper /** * Update single cell reference. * - * @param string $pCellReference Single cell reference - * @param string $pBefore Insert before this one - * @param int $pNumCols Number of columns to increment - * @param int $pNumRows Number of rows to increment + * @param string $cellReference Single cell reference + * @param string $beforeCellAddress Insert before this one + * @param int $numberOfColumns Number of columns to increment + * @param int $numberOfRows Number of rows to increment * * @return string Updated cell reference */ - private function updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) + private function updateSingleCellReference($cellReference = 'A1', $beforeCellAddress = 'A1', $numberOfColumns = 0, $numberOfRows = 0) { - if (Coordinate::coordinateIsRange($pCellReference)) { + if (Coordinate::coordinateIsRange($cellReference)) { throw new Exception('Only single cell references may be passed to this method.'); } - // Get coordinate of $pBefore - [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($pBefore); + // Get coordinate of $beforeCellAddress + [$beforeColumn, $beforeRow] = Coordinate::coordinateFromString($beforeCellAddress); - // Get coordinate of $pCellReference - [$newColumn, $newRow] = Coordinate::coordinateFromString($pCellReference); + // Get coordinate of $cellReference + [$newColumn, $newRow] = Coordinate::coordinateFromString($cellReference); // Verify which parts should be updated $updateColumn = (($newColumn[0] != '$') && ($beforeColumn[0] != '$') && (Coordinate::columnIndexFromString($newColumn) >= Coordinate::columnIndexFromString($beforeColumn))); @@ -1016,12 +1016,12 @@ class ReferenceHelper // Create new column reference if ($updateColumn) { - $newColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($newColumn) + $pNumCols); + $newColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($newColumn) + $numberOfColumns); } // Create new row reference if ($updateRow) { - $newRow = $newRow + $pNumRows; + $newRow = $newRow + $numberOfRows; } // Return new reference diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index d6223528..4d561252 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -71,16 +71,16 @@ class Settings /** * Identify to PhpSpreadsheet the external library to use for rendering charts. * - * @param string $rendererClass Class name of the chart renderer + * @param string $rendererClassName Class name of the chart renderer * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph */ - public static function setChartRenderer(string $rendererClass): void + public static function setChartRenderer(string $rendererClassName): void { - if (!is_a($rendererClass, IRenderer::class, true)) { + if (!is_a($rendererClassName, IRenderer::class, true)) { throw new Exception('Chart renderer must implement ' . IRenderer::class); } - self::$chartRenderer = $rendererClass; + self::$chartRenderer = $rendererClassName; } /** diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 19c11526..4ff00932 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -439,27 +439,27 @@ class Spreadsheet /** * Check if a sheet with a specified code name already exists. * - * @param string $pSheetCodeName Name of the worksheet to check + * @param string $codeName Name of the worksheet to check * * @return bool */ - public function sheetCodeNameExists($pSheetCodeName) + public function sheetCodeNameExists($codeName) { - return $this->getSheetByCodeName($pSheetCodeName) !== null; + return $this->getSheetByCodeName($codeName) !== null; } /** * Get sheet by code name. Warning : sheet don't have always a code name ! * - * @param string $pName Sheet name + * @param string $codeName Sheet name * * @return Worksheet */ - public function getSheetByCodeName($pName) + public function getSheetByCodeName($codeName) { $worksheetCount = count($this->workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { - if ($this->workSheetCollection[$i]->getCodeName() == $pName) { + if ($this->workSheetCollection[$i]->getCodeName() == $codeName) { return $this->workSheetCollection[$i]; } } @@ -545,9 +545,9 @@ class Spreadsheet /** * Set properties. */ - public function setProperties(Document\Properties $pValue): void + public function setProperties(Document\Properties $documentProperties): void { - $this->properties = $pValue; + $this->properties = $documentProperties; } /** @@ -563,9 +563,9 @@ class Spreadsheet /** * Set security. */ - public function setSecurity(Document\Security $pValue): void + public function setSecurity(Document\Security $documentSecurity): void { - $this->security = $pValue; + $this->security = $documentSecurity; } /** @@ -596,76 +596,78 @@ class Spreadsheet /** * Check if a sheet with a specified name already exists. * - * @param string $pSheetName Name of the worksheet to check + * @param string $worksheetName Name of the worksheet to check * * @return bool */ - public function sheetNameExists($pSheetName) + public function sheetNameExists($worksheetName) { - return $this->getSheetByName($pSheetName) !== null; + return $this->getSheetByName($worksheetName) !== null; } /** * Add sheet. * - * @param null|int $iSheetIndex Index where sheet should go (0,1,..., or null for last) + * @param Worksheet $worksheet The worskeet to add + * @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last) * * @return Worksheet + * @throws Exception */ - public function addSheet(Worksheet $pSheet, $iSheetIndex = null) + public function addSheet(Worksheet $worksheet, $sheetIndex = null) { - if ($this->sheetNameExists($pSheet->getTitle())) { + if ($this->sheetNameExists($worksheet->getTitle())) { throw new Exception( - "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first." + "Workbook already contains a worksheet named '{$worksheet->getTitle()}'. Rename this worksheet first." ); } - if ($iSheetIndex === null) { + if ($sheetIndex === null) { if ($this->activeSheetIndex < 0) { $this->activeSheetIndex = 0; } - $this->workSheetCollection[] = $pSheet; + $this->workSheetCollection[] = $worksheet; } else { // Insert the sheet at the requested index array_splice( $this->workSheetCollection, - $iSheetIndex, + $sheetIndex, 0, - [$pSheet] + [$worksheet] ); // Adjust active sheet index if necessary - if ($this->activeSheetIndex >= $iSheetIndex) { + if ($this->activeSheetIndex >= $sheetIndex) { ++$this->activeSheetIndex; } } - if ($pSheet->getParent() === null) { - $pSheet->rebindParent($this); + if ($worksheet->getParent() === null) { + $worksheet->rebindParent($this); } - return $pSheet; + return $worksheet; } /** * Remove sheet by index. * - * @param int $pIndex Active sheet index + * @param int $sheetIndex Index position of the worksheet to remove */ - public function removeSheetByIndex($pIndex): void + public function removeSheetByIndex($sheetIndex): void { $numSheets = count($this->workSheetCollection); - if ($pIndex > $numSheets - 1) { + if ($sheetIndex > $numSheets - 1) { throw new Exception( - "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + "You tried to remove a sheet by the out of bounds index: {$sheetIndex}. The actual number of sheets is {$numSheets}." ); } - array_splice($this->workSheetCollection, $pIndex, 1); + array_splice($this->workSheetCollection, $sheetIndex, 1); // Adjust active sheet index if necessary if ( - ($this->activeSheetIndex >= $pIndex) && - ($pIndex > count($this->workSheetCollection) - 1) + ($this->activeSheetIndex >= $sheetIndex) && + ($sheetIndex > count($this->workSheetCollection) - 1) ) { --$this->activeSheetIndex; } @@ -674,21 +676,21 @@ class Spreadsheet /** * Get sheet by index. * - * @param int $pIndex Sheet index + * @param int $sheetIndex Sheet index * * @return Worksheet */ - public function getSheet($pIndex) + public function getSheet($sheetIndex) { - if (!isset($this->workSheetCollection[$pIndex])) { + if (!isset($this->workSheetCollection[$sheetIndex])) { $numSheets = $this->getSheetCount(); throw new Exception( - "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}." + "Your requested sheet index: {$sheetIndex} is out of bounds. The actual number of sheets is {$numSheets}." ); } - return $this->workSheetCollection[$pIndex]; + return $this->workSheetCollection[$sheetIndex]; } /** @@ -704,15 +706,15 @@ class Spreadsheet /** * Get sheet by name. * - * @param string $pName Sheet name + * @param string $worksheetName Sheet name * * @return null|Worksheet */ - public function getSheetByName($pName) + public function getSheetByName($worksheetName) { $worksheetCount = count($this->workSheetCollection); for ($i = 0; $i < $worksheetCount; ++$i) { - if ($this->workSheetCollection[$i]->getTitle() === trim($pName, "'")) { + if ($this->workSheetCollection[$i]->getTitle() === trim($worksheetName, "'")) { return $this->workSheetCollection[$i]; } } @@ -725,10 +727,10 @@ class Spreadsheet * * @return int index */ - public function getIndex(Worksheet $pSheet) + public function getIndex(Worksheet $worksheet) { foreach ($this->workSheetCollection as $key => $value) { - if ($value->getHashCode() === $pSheet->getHashCode()) { + if ($value->getHashCode() === $worksheet->getHashCode()) { return $key; } } @@ -739,14 +741,14 @@ class Spreadsheet /** * Set index for sheet by sheet name. * - * @param string $sheetName Sheet name to modify index for - * @param int $newIndex New index for the sheet + * @param string $worksheetName Sheet name to modify index for + * @param int $newIndexPosition New index for the sheet * * @return int New sheet index */ - public function setIndexByName($sheetName, $newIndex) + public function setIndexByName($worksheetName, $newIndexPosition) { - $oldIndex = $this->getIndex($this->getSheetByName($sheetName)); + $oldIndex = $this->getIndex($this->getSheetByName($worksheetName)); $pSheet = array_splice( $this->workSheetCollection, $oldIndex, @@ -754,12 +756,12 @@ class Spreadsheet ); array_splice( $this->workSheetCollection, - $newIndex, + $newIndexPosition, 0, $pSheet ); - return $newIndex; + return $newIndexPosition; } /** @@ -785,20 +787,20 @@ class Spreadsheet /** * Set active sheet index. * - * @param int $pIndex Active sheet index + * @param int $worksheetIndex Active sheet index * * @return Worksheet */ - public function setActiveSheetIndex($pIndex) + public function setActiveSheetIndex($worksheetIndex) { $numSheets = count($this->workSheetCollection); - if ($pIndex > $numSheets - 1) { + if ($worksheetIndex > $numSheets - 1) { throw new Exception( - "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + "You tried to set a sheet active by the out of bounds index: {$worksheetIndex}. The actual number of sheets is {$numSheets}." ); } - $this->activeSheetIndex = $pIndex; + $this->activeSheetIndex = $worksheetIndex; return $this->getActiveSheet(); } @@ -806,19 +808,19 @@ class Spreadsheet /** * Set active sheet index by name. * - * @param string $pValue Sheet title + * @param string $worksheetName Sheet title * * @return Worksheet */ - public function setActiveSheetIndexByName($pValue) + public function setActiveSheetIndexByName($worksheetName) { - if (($worksheet = $this->getSheetByName($pValue)) instanceof Worksheet) { + if (($worksheet = $this->getSheetByName($worksheetName)) instanceof Worksheet) { $this->setActiveSheetIndex($this->getIndex($worksheet)); return $worksheet; } - throw new Exception('Workbook does not contain sheet:' . $pValue); + throw new Exception('Workbook does not contain sheet:' . $worksheetName); } /** @@ -840,35 +842,35 @@ class Spreadsheet /** * Add external sheet. * - * @param Worksheet $pSheet External sheet to add - * @param null|int $iSheetIndex Index where sheet should go (0,1,..., or null for last) + * @param Worksheet $worksheet External sheet to add + * @param null|int $sheetIndex Index where sheet should go (0,1,..., or null for last) * * @return Worksheet */ - public function addExternalSheet(Worksheet $pSheet, $iSheetIndex = null) + public function addExternalSheet(Worksheet $worksheet, $sheetIndex = null) { - if ($this->sheetNameExists($pSheet->getTitle())) { - throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); + if ($this->sheetNameExists($worksheet->getTitle())) { + throw new Exception("Workbook already contains a worksheet named '{$worksheet->getTitle()}'. Rename the external sheet first."); } // count how many cellXfs there are in this workbook currently, we will need this below $countCellXfs = count($this->cellXfCollection); // copy all the shared cellXfs from the external workbook and append them to the current - foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) { + foreach ($worksheet->getParent()->getCellXfCollection() as $cellXf) { $this->addCellXf(clone $cellXf); } // move sheet to this workbook - $pSheet->rebindParent($this); + $worksheet->rebindParent($this); // update the cellXfs - foreach ($pSheet->getCoordinates(false) as $coordinate) { - $cell = $pSheet->getCell($coordinate); + foreach ($worksheet->getCoordinates(false) as $coordinate) { + $cell = $worksheet->getCell($coordinate); $cell->setXfIndex($cell->getXfIndex() + $countCellXfs); } - return $this->addSheet($pSheet, $iSheetIndex); + return $this->addSheet($worksheet, $sheetIndex); } /** @@ -948,9 +950,9 @@ class Spreadsheet /** * Get named range. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getNamedRange(string $namedRange, ?Worksheet $pSheet = null): ?NamedRange + public function getNamedRange(string $namedRange, ?Worksheet $worksheet = null): ?NamedRange { $returnValue = null; @@ -959,7 +961,7 @@ class Spreadsheet // first look for global named range $returnValue = $this->getGlobalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE); // then look for local named range (has priority over global named range if both names exist) - $returnValue = $this->getLocalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE, $pSheet) ?: $returnValue; + $returnValue = $this->getLocalDefinedNameByType($namedRange, self::DEFINED_NAME_IS_RANGE, $worksheet) ?: $returnValue; } return $returnValue instanceof NamedRange ? $returnValue : null; @@ -968,9 +970,9 @@ class Spreadsheet /** * Get named formula. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getNamedFormula(string $namedFormula, ?Worksheet $pSheet = null): ?NamedFormula + public function getNamedFormula(string $namedFormula, ?Worksheet $worksheet = null): ?NamedFormula { $returnValue = null; @@ -979,7 +981,7 @@ class Spreadsheet // first look for global named formula $returnValue = $this->getGlobalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA); // then look for local named formula (has priority over global named formula if both names exist) - $returnValue = $this->getLocalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA, $pSheet) ?: $returnValue; + $returnValue = $this->getLocalDefinedNameByType($namedFormula, self::DEFINED_NAME_IS_FORMULA, $worksheet) ?: $returnValue; } return $returnValue instanceof NamedFormula ? $returnValue : null; @@ -1009,9 +1011,9 @@ class Spreadsheet /** * Get named range. * - * @param null|Worksheet $pSheet Scope. Use null for global scope + * @param null|Worksheet $worksheet Scope. Use null for global scope */ - public function getDefinedName(string $definedName, ?Worksheet $pSheet = null): ?DefinedName + public function getDefinedName(string $definedName, ?Worksheet $worksheet = null): ?DefinedName { $returnValue = null; @@ -1023,8 +1025,8 @@ class Spreadsheet } // then look for local defined name (has priority over global defined name if both names exist) - if (($pSheet !== null) && isset($this->definedNames[$pSheet->getTitle() . '!' . $definedName])) { - $returnValue = $this->definedNames[$pSheet->getTitle() . '!' . $definedName]; + if (($worksheet !== null) && isset($this->definedNames[$worksheet->getTitle() . '!' . $definedName])) { + $returnValue = $this->definedNames[$worksheet->getTitle() . '!' . $definedName]; } } @@ -1034,53 +1036,53 @@ class Spreadsheet /** * Remove named range. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeNamedRange(string $namedRange, ?Worksheet $pSheet = null): self + public function removeNamedRange(string $namedRange, ?Worksheet $worksheet = null): self { - if ($this->getNamedRange($namedRange, $pSheet) === null) { + if ($this->getNamedRange($namedRange, $worksheet) === null) { return $this; } - return $this->removeDefinedName($namedRange, $pSheet); + return $this->removeDefinedName($namedRange, $worksheet); } /** * Remove named formula. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeNamedFormula(string $namedFormula, ?Worksheet $pSheet = null): self + public function removeNamedFormula(string $namedFormula, ?Worksheet $worksheet = null): self { - if ($this->getNamedFormula($namedFormula, $pSheet) === null) { + if ($this->getNamedFormula($namedFormula, $worksheet) === null) { return $this; } - return $this->removeDefinedName($namedFormula, $pSheet); + return $this->removeDefinedName($namedFormula, $worksheet); } /** * Remove defined name. * - * @param null|Worksheet $pSheet scope: use null for global scope + * @param null|Worksheet $worksheet scope: use null for global scope * * @return $this */ - public function removeDefinedName(string $definedName, ?Worksheet $pSheet = null): self + public function removeDefinedName(string $definedName, ?Worksheet $worksheet = null): self { $definedName = StringHelper::strToUpper($definedName); - if ($pSheet === null) { + if ($worksheet === null) { if (isset($this->definedNames[$definedName])) { unset($this->definedNames[$definedName]); } } else { - if (isset($this->definedNames[$pSheet->getTitle() . '!' . $definedName])) { - unset($this->definedNames[$pSheet->getTitle() . '!' . $definedName]); + if (isset($this->definedNames[$worksheet->getTitle() . '!' . $definedName])) { + unset($this->definedNames[$worksheet->getTitle() . '!' . $definedName]); } elseif (isset($this->definedNames[$definedName])) { unset($this->definedNames[$definedName]); } @@ -1142,26 +1144,26 @@ class Spreadsheet /** * Get cellXf by index. * - * @param int $pIndex + * @param int $cellStyleIndex * * @return Style */ - public function getCellXfByIndex($pIndex) + public function getCellXfByIndex($cellStyleIndex) { - return $this->cellXfCollection[$pIndex]; + return $this->cellXfCollection[$cellStyleIndex]; } /** * Get cellXf by hash code. * - * @param string $pValue + * @param string $hashcode * * @return false|Style */ - public function getCellXfByHashCode($pValue) + public function getCellXfByHashCode($hashcode) { foreach ($this->cellXfCollection as $cellXf) { - if ($cellXf->getHashCode() === $pValue) { + if ($cellXf->getHashCode() === $hashcode) { return $cellXf; } } @@ -1172,13 +1174,13 @@ class Spreadsheet /** * Check if style exists in style collection. * - * @param Style $pCellStyle + * @param Style $cellStyleIndex * * @return bool */ - public function cellXfExists($pCellStyle) + public function cellXfExists($cellStyleIndex) { - return in_array($pCellStyle, $this->cellXfCollection, true); + return in_array($cellStyleIndex, $this->cellXfCollection, true); } /** @@ -1207,26 +1209,26 @@ class Spreadsheet /** * Remove cellXf by index. It is ensured that all cells get their xf index updated. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf */ - public function removeCellXfByIndex($pIndex): void + public function removeCellXfByIndex($cellStyleIndex): void { - if ($pIndex > count($this->cellXfCollection) - 1) { + if ($cellStyleIndex > count($this->cellXfCollection) - 1) { throw new Exception('CellXf index is out of bounds.'); } // first remove the cellXf - array_splice($this->cellXfCollection, $pIndex, 1); + array_splice($this->cellXfCollection, $cellStyleIndex, 1); // then update cellXf indexes for cells foreach ($this->workSheetCollection as $worksheet) { foreach ($worksheet->getCoordinates(false) as $coordinate) { $cell = $worksheet->getCell($coordinate); $xfIndex = $cell->getXfIndex(); - if ($xfIndex > $pIndex) { + if ($xfIndex > $cellStyleIndex) { // decrease xf index by 1 $cell->setXfIndex($xfIndex - 1); - } elseif ($xfIndex == $pIndex) { + } elseif ($xfIndex == $cellStyleIndex) { // set to default xf index 0 $cell->setXfIndex(0); } @@ -1257,26 +1259,26 @@ class Spreadsheet /** * Get cellStyleXf by index. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf * * @return Style */ - public function getCellStyleXfByIndex($pIndex) + public function getCellStyleXfByIndex($cellStyleIndex) { - return $this->cellStyleXfCollection[$pIndex]; + return $this->cellStyleXfCollection[$cellStyleIndex]; } /** * Get cellStyleXf by hash code. * - * @param string $pValue + * @param string $hashcode * * @return false|Style */ - public function getCellStyleXfByHashCode($pValue) + public function getCellStyleXfByHashCode($hashcode) { foreach ($this->cellStyleXfCollection as $cellStyleXf) { - if ($cellStyleXf->getHashCode() === $pValue) { + if ($cellStyleXf->getHashCode() === $hashcode) { return $cellStyleXf; } } @@ -1287,23 +1289,23 @@ class Spreadsheet /** * Add a cellStyleXf to the workbook. */ - public function addCellStyleXf(Style $pStyle): void + public function addCellStyleXf(Style $style): void { - $this->cellStyleXfCollection[] = $pStyle; - $pStyle->setIndex(count($this->cellStyleXfCollection) - 1); + $this->cellStyleXfCollection[] = $style; + $style->setIndex(count($this->cellStyleXfCollection) - 1); } /** * Remove cellStyleXf by index. * - * @param int $pIndex Index to cellXf + * @param int $cellStyleIndex Index to cellXf */ - public function removeCellStyleXfByIndex($pIndex): void + public function removeCellStyleXfByIndex($cellStyleIndex): void { - if ($pIndex > count($this->cellStyleXfCollection) - 1) { + if ($cellStyleIndex > count($this->cellStyleXfCollection) - 1) { throw new Exception('CellStyleXf index is out of bounds.'); } - array_splice($this->cellStyleXfCollection, $pIndex, 1); + array_splice($this->cellStyleXfCollection, $cellStyleIndex, 1); } /**