33        if (!isset(self::$instance) || (self::$instance === 
null)) {
 
   34            self::$instance = 
new self();
 
   58        return strcasecmp(strlen($a) . $a, strlen($b) . $b);
 
   72        return -strcasecmp(strlen($a) . $a, strlen($b) . $b);
 
   86        [$ac, $ar] = sscanf($a, 
'%[A-Z]%d');
 
   87        [$bc, $br] = sscanf($b, 
'%[A-Z]%d');
 
   90            return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
 
   93        return ($ar < $br) ? -1 : 1;
 
  107        [$ac, $ar] = sscanf($a, 
'%[A-Z]%d');
 
  108        [$bc, $br] = sscanf($b, 
'%[A-Z]%d');
 
  111            return -strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
 
  114        return ($ar < $br) ? 1 : -1;
 
  135            ($cellRow >= ($beforeRow + $pNumRows)) &&
 
  136            ($cellRow < $beforeRow)
 
  141            ($cellColumnIndex >= ($beforeColumnIndex + $pNumCols)) &&
 
  142            ($cellColumnIndex < $beforeColumnIndex)
 
  162        $aBreaks = $pSheet->getBreaks();
 
  163        ($pNumCols > 0 || $pNumRows > 0) ?
 
  164            uksort($aBreaks, [
'self', 
'cellReverseSort']) : uksort($aBreaks, [
'self', 
'cellSort']);
 
  166        foreach ($aBreaks as 
$key => $value) {
 
  167            if (self::cellAddressInDeleteRange(
$key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) {
 
  175                if (
$key != $newReference) {
 
  176                    $pSheet->setBreak($newReference, $value)
 
  193    protected function adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  195        $aComments = $pSheet->getComments();
 
  198        foreach ($aComments as 
$key => &$value) {
 
  200            if (!self::cellAddressInDeleteRange(
$key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) {
 
  203                $aNewComments[$newReference] = $value;
 
  207        $pSheet->setComments($aNewComments);
 
  220    protected function adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  222        $aHyperlinkCollection = $pSheet->getHyperlinkCollection();
 
  223        ($pNumCols > 0 || $pNumRows > 0) ?
 
  224            uksort($aHyperlinkCollection, [
'self', 
'cellReverseSort']) : uksort($aHyperlinkCollection, [
'self', 
'cellSort']);
 
  226        foreach ($aHyperlinkCollection as 
$key => $value) {
 
  228            if (
$key != $newReference) {
 
  229                $pSheet->setHyperlink($newReference, $value);
 
  230                $pSheet->setHyperlink(
$key, 
null);
 
  245    protected function adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  247        $aDataValidationCollection = $pSheet->getDataValidationCollection();
 
  248        ($pNumCols > 0 || $pNumRows > 0) ?
 
  249            uksort($aDataValidationCollection, [
'self', 
'cellReverseSort']) : uksort($aDataValidationCollection, [
'self', 
'cellSort']);
 
  251        foreach ($aDataValidationCollection as 
$key => $value) {
 
  253            if (
$key != $newReference) {
 
  254                $pSheet->setDataValidation($newReference, $value);
 
  255                $pSheet->setDataValidation(
$key, 
null);
 
  270    protected function adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  272        $aMergeCells = $pSheet->getMergeCells();
 
  273        $aNewMergeCells = []; 
 
  274        foreach ($aMergeCells as 
$key => &$value) {
 
  276            $aNewMergeCells[$newReference] = $newReference;
 
  278        $pSheet->setMergeCells($aNewMergeCells); 
 
  291    protected function adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  293        $aProtectedCells = $pSheet->getProtectedCells();
 
  294        ($pNumCols > 0 || $pNumRows > 0) ?
 
  295            uksort($aProtectedCells, [
'self', 
'cellReverseSort']) : uksort($aProtectedCells, [
'self', 
'cellSort']);
 
  296        foreach ($aProtectedCells as 
$key => $value) {
 
  298            if (
$key != $newReference) {
 
  299                $pSheet->protectCells($newReference, $value, 
true);
 
  300                $pSheet->unprotectCells(
$key);
 
  317        $aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), 
true);
 
  318        if (!empty($aColumnDimensions)) {
 
  319            foreach ($aColumnDimensions as $objColumnDimension) {
 
  320                $newReference = $this->
updateCellReference($objColumnDimension->getColumnIndex() . 
'1', $pBefore, $pNumCols, $pNumRows);
 
  322                if ($objColumnDimension->getColumnIndex() != $newReference) {
 
  323                    $objColumnDimension->setColumnIndex($newReference);
 
  326            $pSheet->refreshColumnDimensions();
 
  340    protected function adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows): void
 
  342        $aRowDimensions = array_reverse($pSheet->getRowDimensions(), 
true);
 
  343        if (!empty($aRowDimensions)) {
 
  344            foreach ($aRowDimensions as $objRowDimension) {
 
  345                $newReference = $this->
updateCellReference(
'A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows);
 
  347                if ($objRowDimension->getRowIndex() != $newReference) {
 
  348                    $objRowDimension->setRowIndex($newReference);
 
  351            $pSheet->refreshRowDimensions();
 
  353            $copyDimension = $pSheet->getRowDimension($beforeRow - 1);
 
  354            for (
$i = $beforeRow; 
$i <= $beforeRow - 1 + $pNumRows; ++
$i) {
 
  355                $newDimension = $pSheet->getRowDimension(
$i);
 
  356                $newDimension->setRowHeight($copyDimension->getRowHeight());
 
  357                $newDimension->setVisible($copyDimension->getVisible());
 
  358                $newDimension->setOutlineLevel($copyDimension->getOutlineLevel());
 
  359                $newDimension->setCollapsed($copyDimension->getCollapsed());
 
  374        $remove = ($pNumCols < 0 || $pNumRows < 0);
 
  375        $allCoordinates = $pSheet->getCoordinates();
 
  381        $highestColumn = $pSheet->getHighestColumn();
 
  382        $highestRow = $pSheet->getHighestRow();
 
  385        if ($pNumCols < 0 && $beforeColumn - 2 + $pNumCols > 0) {
 
  386            for (
$i = 1; 
$i <= $highestRow - 1; ++
$i) {
 
  387                for ($j = $beforeColumn - 1 + $pNumCols; $j <= $beforeColumn - 2; ++$j) {
 
  389                    $pSheet->removeConditionalStyles($coordinate);
 
  390                    if ($pSheet->cellExists($coordinate)) {
 
  392                        $pSheet->getCell($coordinate)->setXfIndex(0);
 
  399        if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) {
 
  401                for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) {
 
  403                    $pSheet->removeConditionalStyles($coordinate);
 
  404                    if ($pSheet->cellExists($coordinate)) {
 
  406                        $pSheet->getCell($coordinate)->setXfIndex(0);
 
  415            $allCoordinates = array_reverse($allCoordinates);
 
  417        while ($coordinate = array_pop($allCoordinates)) {
 
  418            $cell = $pSheet->getCell($coordinate);
 
  421            if ($cellIndex - 1 + $pNumCols < 0) {
 
  429            if (($cellIndex >= $beforeColumn) && ($cell->getRow() >= $beforeRow)) {
 
  431                $pSheet->getCell($newCoordinate)->setXfIndex($cell->getXfIndex());
 
  436                    $pSheet->getCell($newCoordinate)
 
  437                        ->setValue($this->
updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
 
  440                    $pSheet->getCell($newCoordinate)->setValue($cell->getValue());
 
  444                $pSheet->getCellCollection()->delete($coordinate);
 
  450                    $cell->setValue($this->
updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
 
  456        $highestColumn = $pSheet->getHighestColumn();
 
  457        $highestRow = $pSheet->getHighestRow();
 
  459        if ($pNumCols > 0 && $beforeColumn - 2 > 0) {
 
  460            for (
$i = $beforeRow; 
$i <= $highestRow - 1; ++
$i) {
 
  463                if ($pSheet->cellExists($coordinate)) {
 
  464                    $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
 
  465                    $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ?
 
  466                        $pSheet->getConditionalStyles($coordinate) : 
false;
 
  467                    for ($j = $beforeColumn; $j <= $beforeColumn - 1 + $pNumCols; ++$j) {
 
  468                        $pSheet->getCellByColumnAndRow($j, 
$i)->setXfIndex($xfIndex);
 
  469                        if ($conditionalStyles) {
 
  471                            foreach ($conditionalStyles as $conditionalStyle) {
 
  472                                $cloned[] = clone $conditionalStyle;
 
  481        if ($pNumRows > 0 && $beforeRow - 1 > 0) {
 
  485                if ($pSheet->cellExists($coordinate)) {
 
  486                    $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
 
  487                    $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ?
 
  488                        $pSheet->getConditionalStyles($coordinate) : 
false;
 
  489                    for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) {
 
  491                        if ($conditionalStyles) {
 
  493                            foreach ($conditionalStyles as $conditionalStyle) {
 
  494                                $cloned[] = clone $conditionalStyle;
 
  507        $this->
adjustRowDimensions($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  510        $this->
adjustPageBreaks($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  513        $this->
adjustComments($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  516        $this->
adjustHyperlinks($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  522        $this->
adjustMergeCells($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  525        $this->
adjustProtectedCells($pSheet, $pBefore, $beforeColumn, $pNumCols, $beforeRow, $pNumRows);
 
  528        $autoFilter = $pSheet->getAutoFilter();
 
  529        $autoFilterRange = $autoFilter->getRange();
 
  530        if (!empty($autoFilterRange)) {
 
  531            if ($pNumCols != 0) {
 
  532                $autoFilterColumns = $autoFilter->getColumns();
 
  533                if (count($autoFilterColumns) > 0) {
 
  536                    sscanf($pBefore, 
'%[A-Z]%d', $column, 
$row);
 
  539                    if ($columnIndex <= $rangeEnd[0]) {
 
  543                            $deleteColumn = $columnIndex + $pNumCols - 1;
 
  544                            $deleteCount = abs($pNumCols);
 
  545                            for (
$i = 1; 
$i <= $deleteCount; ++
$i) {
 
  552                        $startCol = ($columnIndex > $rangeStart[0]) ? $columnIndex : $rangeStart[0];
 
  556                            $startColRef = $startCol;
 
  557                            $endColRef = $rangeEnd[0];
 
  558                            $toColRef = $rangeEnd[0] + $pNumCols;
 
  564                            } 
while ($startColRef <= $endColRef);
 
  571                                $autoFilter->shiftColumn($startColID, $toColID);
 
  574                            } 
while ($startColID != $endColID);
 
  579            $pSheet->setAutoFilter($this->
updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows));
 
  583        if ($pSheet->getFreezePane()) {
 
  584            $splitCell = $pSheet->getFreezePane();
 
  585            $topLeftCell = $pSheet->getTopLeftCell();
 
  590            $pSheet->freezePane($splitCell, $topLeftCell);
 
  594        if ($pSheet->getPageSetup()->isPrintAreaSet()) {
 
  595            $pSheet->getPageSetup()->setPrintArea($this->
updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows));
 
  599        $aDrawings = $pSheet->getDrawingCollection();
 
  600        foreach ($aDrawings as $objDrawing) {
 
  601            $newReference = $this->
updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows);
 
  602            if ($objDrawing->getCoordinates() != $newReference) {
 
  603                $objDrawing->setCoordinates($newReference);
 
  608        if (count($pSheet->getParent()->getDefinedNames()) > 0) {
 
  609            foreach ($pSheet->getParent()->getDefinedNames() as $definedName) {
 
  610                if ($definedName->getWorksheet() !== 
null && $definedName->getWorksheet()->getHashCode() === $pSheet->
getHashCode()) {
 
  611                    $definedName->setValue($this->
updateCellReference($definedName->getValue(), $pBefore, $pNumCols, $pNumRows));
 
  617        $pSheet->garbageCollect();
 
  634        $formulaBlocks = explode(
'"', $pFormula);
 
  636        foreach ($formulaBlocks as &$formulaBlock) {
 
  640                $newCellTokens = $cellTokens = [];
 
  642                $matchCount = preg_match_all(
'/' . self::REFHELPER_REGEXP_ROWRANGE . 
'/i', 
' ' . $formulaBlock . 
' ', $matches, PREG_SET_ORDER);
 
  643                if ($matchCount > 0) {
 
  644                    foreach ($matches as $match) {
 
  645                        $fromString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  646                        $fromString .= $match[3] . 
':' . $match[4];
 
  647                        $modified3 = substr($this->
updateCellReference(
'$A' . $match[3], $pBefore, $pNumCols, $pNumRows), 2);
 
  648                        $modified4 = substr($this->
updateCellReference(
'$A' . $match[4], $pBefore, $pNumCols, $pNumRows), 2);
 
  650                        if ($match[3] . 
':' . $match[4] !== $modified3 . 
':' . $modified4) {
 
  651                            if (($match[2] == 
'') || (trim($match[2], 
"'") == $sheetName)) {
 
  652                                $toString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  653                                $toString .= $modified3 . 
':' . $modified4;
 
  656                                $row = 10000000 + (int) trim($match[3], 
'$');
 
  657                                $cellIndex = $column . 
$row;
 
  659                                $newCellTokens[$cellIndex] = preg_quote($toString, 
'/');
 
  660                                $cellTokens[$cellIndex] = 
'/(?<!\d\$\!)' . preg_quote($fromString, 
'/') . 
'(?!\d)/i';
 
  667                $matchCount = preg_match_all(
'/' . self::REFHELPER_REGEXP_COLRANGE . 
'/i', 
' ' . $formulaBlock . 
' ', $matches, PREG_SET_ORDER);
 
  668                if ($matchCount > 0) {
 
  669                    foreach ($matches as $match) {
 
  670                        $fromString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  671                        $fromString .= $match[3] . 
':' . $match[4];
 
  672                        $modified3 = substr($this->
updateCellReference($match[3] . 
'$1', $pBefore, $pNumCols, $pNumRows), 0, -2);
 
  673                        $modified4 = substr($this->
updateCellReference($match[4] . 
'$1', $pBefore, $pNumCols, $pNumRows), 0, -2);
 
  675                        if ($match[3] . 
':' . $match[4] !== $modified3 . 
':' . $modified4) {
 
  676                            if (($match[2] == 
'') || (trim($match[2], 
"'") == $sheetName)) {
 
  677                                $toString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  678                                $toString .= $modified3 . 
':' . $modified4;
 
  682                                $cellIndex = $column . 
$row;
 
  684                                $newCellTokens[$cellIndex] = preg_quote($toString, 
'/');
 
  685                                $cellTokens[$cellIndex] = 
'/(?<![A-Z\$\!])' . preg_quote($fromString, 
'/') . 
'(?![A-Z])/i';
 
  692                $matchCount = preg_match_all(
'/' . self::REFHELPER_REGEXP_CELLRANGE . 
'/i', 
' ' . $formulaBlock . 
' ', $matches, PREG_SET_ORDER);
 
  693                if ($matchCount > 0) {
 
  694                    foreach ($matches as $match) {
 
  695                        $fromString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  696                        $fromString .= $match[3] . 
':' . $match[4];
 
  700                        if ($match[3] . $match[4] !== $modified3 . $modified4) {
 
  701                            if (($match[2] == 
'') || (trim($match[2], 
"'") == $sheetName)) {
 
  702                                $toString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  703                                $toString .= $modified3 . 
':' . $modified4;
 
  707                                $row = (int) trim(
$row, 
'$') + 10000000;
 
  708                                $cellIndex = $column . 
$row;
 
  710                                $newCellTokens[$cellIndex] = preg_quote($toString, 
'/');
 
  711                                $cellTokens[$cellIndex] = 
'/(?<![A-Z]\$\!)' . preg_quote($fromString, 
'/') . 
'(?!\d)/i';
 
  718                $matchCount = preg_match_all(
'/' . self::REFHELPER_REGEXP_CELLREF . 
'/i', 
' ' . $formulaBlock . 
' ', $matches, PREG_SET_ORDER);
 
  720                if ($matchCount > 0) {
 
  721                    foreach ($matches as $match) {
 
  722                        $fromString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  723                        $fromString .= $match[3];
 
  726                        if ($match[3] !== $modified3) {
 
  727                            if (($match[2] == 
'') || (trim($match[2], 
"'") == $sheetName)) {
 
  728                                $toString = ($match[2] > 
'') ? $match[2] . 
'!' : 
'';
 
  729                                $toString .= $modified3;
 
  733                                $row = (int) trim(
$row, 
'$') + 10000000;
 
  734                                $cellIndex = 
$row . $column;
 
  736                                $newCellTokens[$cellIndex] = preg_quote($toString, 
'/');
 
  737                                $cellTokens[$cellIndex] = 
'/(?<![A-Z\$\!])' . preg_quote($fromString, 
'/') . 
'(?!\d)/i';
 
  743                if ($adjustCount > 0) {
 
  744                    if ($pNumCols > 0 || $pNumRows > 0) {
 
  746                        krsort($newCellTokens);
 
  749                        ksort($newCellTokens);
 
  751                    $formulaBlock = str_replace(
'\\', 
'', preg_replace($cellTokens, $newCellTokens, $formulaBlock));
 
  755        unset($formulaBlock);
 
  758        return implode(
'"', $formulaBlocks);
 
  768        if ($insertColumns !== 0) {
 
  772        if ($insertRows !== 0) {
 
  781        $splitCount = preg_match_all(
 
  788        $columnLengths = array_map(
'strlen', array_column($splitRanges[6], 0));
 
  789        $rowLengths = array_map(
'strlen', array_column($splitRanges[7], 0));
 
  790        $columnOffsets = array_column($splitRanges[6], 1);
 
  791        $rowOffsets = array_column($splitRanges[7], 1);
 
  794        $rows = $splitRanges[7];
 
  796        while ($splitCount > 0) {
 
  798            $columnLength = $columnLengths[$splitCount];
 
  799            $rowLength = $rowLengths[$splitCount];
 
  800            $columnOffset = $columnOffsets[$splitCount];
 
  801            $rowOffset = $rowOffsets[$splitCount];
 
  805            if (!empty($column) && $column[0] !== 
'$') {
 
  807                $formula = substr($formula, 0, $columnOffset) . $column . substr($formula, $columnOffset + $columnLength);
 
  809            if (!empty(
$row) && 
$row[0] !== 
'$') {
 
  811                $formula = substr($formula, 0, $rowOffset) . 
$row . substr($formula, $rowOffset + $rowLength);
 
  820        $splitCount = preg_match_all(
 
  827        $fromColumnLengths = array_map(
'strlen', array_column($splitRanges[1], 0));
 
  828        $fromColumnOffsets = array_column($splitRanges[1], 1);
 
  829        $toColumnLengths = array_map(
'strlen', array_column($splitRanges[2], 0));
 
  830        $toColumnOffsets = array_column($splitRanges[2], 1);
 
  832        $fromColumns = $splitRanges[1];
 
  833        $toColumns = $splitRanges[2];
 
  835        while ($splitCount > 0) {
 
  837            $fromColumnLength = $fromColumnLengths[$splitCount];
 
  838            $toColumnLength = $toColumnLengths[$splitCount];
 
  839            $fromColumnOffset = $fromColumnOffsets[$splitCount];
 
  840            $toColumnOffset = $toColumnOffsets[$splitCount];
 
  841            $fromColumn = $fromColumns[$splitCount][0];
 
  842            $toColumn = $toColumns[$splitCount][0];
 
  844            if (!empty($fromColumn) && $fromColumn[0] !== 
'$') {
 
  846                $formula = substr($formula, 0, $fromColumnOffset) . $fromColumn . substr($formula, $fromColumnOffset + $fromColumnLength);
 
  848            if (!empty($toColumn) && $toColumn[0] !== 
'$') {
 
  850                $formula = substr($formula, 0, $toColumnOffset) . $toColumn . substr($formula, $toColumnOffset + $toColumnLength);
 
  859        $splitCount = preg_match_all(
 
  866        $fromRowLengths = array_map(
'strlen', array_column($splitRanges[1], 0));
 
  867        $fromRowOffsets = array_column($splitRanges[1], 1);
 
  868        $toRowLengths = array_map(
'strlen', array_column($splitRanges[2], 0));
 
  869        $toRowOffsets = array_column($splitRanges[2], 1);
 
  871        $fromRows = $splitRanges[1];
 
  872        $toRows = $splitRanges[2];
 
  874        while ($splitCount > 0) {
 
  876            $fromRowLength = $fromRowLengths[$splitCount];
 
  877            $toRowLength = $toRowLengths[$splitCount];
 
  878            $fromRowOffset = $fromRowOffsets[$splitCount];
 
  879            $toRowOffset = $toRowOffsets[$splitCount];
 
  880            $fromRow = $fromRows[$splitCount][0];
 
  881            $toRow = $toRows[$splitCount][0];
 
  883            if (!empty($fromRow) && $fromRow[0] !== 
'$') {
 
  884                $fromRow += $insertRows;
 
  885                $formula = substr($formula, 0, $fromRowOffset) . $fromRow . substr($formula, $fromRowOffset + $fromRowLength);
 
  887            if (!empty($toRow) && $toRow[0] !== 
'$') {
 
  888                $toRow += $insertRows;
 
  889                $formula = substr($formula, 0, $toRowOffset) . $toRow . substr($formula, $toRowOffset + $toRowLength);
 
  909        if (strpos($pCellRange, 
'!') !== 
false) {
 
  917            return $this->
updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows);
 
  933        if ($oldName == 
'') {
 
  938            foreach ($sheet->getCoordinates(
false) as $coordinate) {
 
  939                $cell = $sheet->getCell($coordinate);
 
  941                    $formula = $cell->getValue();
 
  942                    if (strpos($formula, $oldName) !== 
false) {
 
  943                        $formula = str_replace(
"'" . $oldName . 
"'!", 
"'" . $newName . 
"'!", $formula);
 
  944                        $formula = str_replace($oldName . 
'!', $newName . 
'!', $formula);
 
  962    private function updateCellRange($pCellRange = 
'A1:A1', $pBefore = 
'A1', $pNumCols = 0, $pNumRows = 0)
 
  965            throw new Exception(
'Only cell ranges may be passed to this method.');
 
  971        for (
$i = 0; 
$i < $ic; ++
$i) {
 
  972            $jc = count($range[
$i]);
 
  973            for ($j = 0; $j < $jc; ++$j) {
 
  974                if (ctype_alpha($range[
$i][$j])) {
 
  976                    $range[
$i][$j] = 
$r[0];
 
  977                } elseif (ctype_digit($range[
$i][$j])) {
 
  979                    $range[
$i][$j] = 
$r[1];
 
 1003            throw new Exception(
'Only single cell references may be passed to this method.');
 
 1014        $updateRow = (($newRow[0] != 
'$') && ($beforeRow[0] != 
'$') && $newRow >= $beforeRow);
 
 1017        if ($updateColumn) {
 
 1023            $newRow = (int) $newRow + $pNumRows;
 
 1027        return $newColumn . $newRow;
 
 1035        throw new Exception(
'Cloning a Singleton is not allowed!');
 
An exception for terminatinating execution or to throw for unit testing.
const CALCULATION_REGEXP_CELLREF_RELATIVE
const CALCULATION_REGEXP_ROWRANGE_RELATIVE
const CALCULATION_REGEXP_COLUMNRANGE_RELATIVE
Helper class to manipulate cell coordinates.
static coordinateFromString($pCoordinateString)
Coordinate from string.
static coordinateIsRange($coord)
Checks if a coordinate represents a range of cells.
static indexesFromString(string $coordinates)
Get indexes from a string coordinates.
static columnIndexFromString($pString)
Column index from string.
static stringFromColumnIndex($columnIndex)
String from column index.
static splitRange($pRange)
Split range into coordinate strings.
static buildRange(array $pRange)
Build range from coordinate strings.
static rangeBoundaries($pRange)
Calculate range boundaries.
adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update column dimensions when inserting/deleting rows/columns.
updateCellReferencesAllWorksheets(string $formula, int $insertColumns, int $insertRows)
adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update data validations when inserting/deleting rows/columns.
updateCellReference($pCellRange='A1', $pBefore='A1', $pNumCols=0, $pNumRows=0)
Update cell reference.
const REFHELPER_REGEXP_CELLRANGE
insertNewBefore($pBefore, $pNumCols, $pNumRows, Worksheet $pSheet)
Insert a new column or row, updating all possible related data.
static columnSort($a, $b)
Compare two column addresses Intended for use as a Callback function for sorting column addresses by ...
adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update merged cells when inserting/deleting rows/columns.
__construct()
Create a new ReferenceHelper.
adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update row dimensions when inserting/deleting rows/columns.
static cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)
Test whether a cell address falls within a defined range of cells.
const REFHELPER_REGEXP_CELLREF
Constants
adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update hyperlinks when inserting/deleting rows/columns.
adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update protected cells when inserting/deleting rows/columns.
static columnReverseSort($a, $b)
Compare two column addresses Intended for use as a Callback function for reverse sorting column addre...
static getInstance()
Get an instance of this class.
updateFormulaReferencesAnyWorksheet(string $formula='', int $insertColumns=0, int $insertRows=0)
Update all cell references within a formula, irrespective of worksheet.
static cellReverseSort($a, $b)
Compare two cell addresses Intended for use as a Callback function for sorting cell addresses by colu...
updateNamedFormulas(Spreadsheet $spreadsheet, $oldName='', $newName='')
Update named formulas (i.e.
updateFormulaReferences($pFormula='', $pBefore='A1', $pNumCols=0, $pNumRows=0, $sheetName='')
Update references within formulas.
static cellSort($a, $b)
Compare two cell addresses Intended for use as a Callback function for sorting cell addresses by colu...
updateCellRange($pCellRange='A1:A1', $pBefore='A1', $pNumCols=0, $pNumRows=0)
Update cell range.
__clone()
__clone implementation.
adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update cell comments when inserting/deleting rows/columns.
updateSingleCellReference($pCellReference='A1', $pBefore='A1', $pNumCols=0, $pNumRows=0)
Update single cell reference.
updateColumnRangesAllWorksheets(string $formula, int $insertColumns)
adjustPageBreaks(Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows)
Update page breaks when inserting/deleting rows/columns.
const REFHELPER_REGEXP_ROWRANGE
const REFHELPER_REGEXP_COLRANGE
updateRowRangesAllWorksheets(string $formula, int $insertRows)
getWorksheetIterator()
Get worksheet iterator.
getHashCode()
Get hash code.