Additional work on GH-161 - Fix: Hyperlinks break when removing rows
This commit is contained in:
parent
ab01a6c6dc
commit
097ae1706e
|
@ -73,7 +73,7 @@ class PHPExcel_ReferenceHelper
|
||||||
list($bc,$br) = sscanf($b,'%[A-Z]%d');
|
list($bc,$br) = sscanf($b,'%[A-Z]%d');
|
||||||
|
|
||||||
if ($ar == $br) {
|
if ($ar == $br) {
|
||||||
return strcasecmp(sprintf('%03s',$ac), sprintf('%03s',$bc));
|
return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
|
||||||
}
|
}
|
||||||
return ($ar < $br) ? -1 : 1;
|
return ($ar < $br) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ class PHPExcel_ReferenceHelper
|
||||||
list($bc,$br) = sscanf($b,'%[A-Z]%d');
|
list($bc,$br) = sscanf($b,'%[A-Z]%d');
|
||||||
|
|
||||||
if ($ar == $br) {
|
if ($ar == $br) {
|
||||||
return 1 - strcasecmp(sprintf('%03s',$ac), sprintf('%03s',$bc));
|
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc);
|
||||||
}
|
}
|
||||||
return ($ar < $br) ? 1 : -1;
|
return ($ar < $br) ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,6 @@ class PHPExcel_ReferenceHelper
|
||||||
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
|
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
|
||||||
$beforeColumnIndex = PHPExcel_Cell::columnIndexFromString($beforeColumn);
|
$beforeColumnIndex = PHPExcel_Cell::columnIndexFromString($beforeColumn);
|
||||||
|
|
||||||
|
|
||||||
// Clear cells if we are removing columns or rows
|
// Clear cells if we are removing columns or rows
|
||||||
$highestColumn = $pSheet->getHighestColumn();
|
$highestColumn = $pSheet->getHighestColumn();
|
||||||
$highestRow = $pSheet->getHighestRow();
|
$highestRow = $pSheet->getHighestRow();
|
||||||
|
@ -139,7 +138,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Loop through cells, bottom-up, and change cell coordinates
|
// Loop through cells, bottom-up, and change cell coordinates
|
||||||
while (($cellID = $remove ? array_shift($aCellCollection) : array_pop($aCellCollection))) {
|
while (($cellID = $remove ? array_shift($aCellCollection) : array_pop($aCellCollection))) {
|
||||||
$cell = $pSheet->getCell($cellID);
|
$cell = $pSheet->getCell($cellID);
|
||||||
|
@ -184,7 +182,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Duplicate styles for the newly inserted cells
|
// Duplicate styles for the newly inserted cells
|
||||||
$highestColumn = $pSheet->getHighestColumn();
|
$highestColumn = $pSheet->getHighestColumn();
|
||||||
$highestRow = $pSheet->getHighestRow();
|
$highestRow = $pSheet->getHighestRow();
|
||||||
|
@ -236,7 +233,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: column dimensions
|
// Update worksheet: column dimensions
|
||||||
$aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true);
|
$aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true);
|
||||||
if (!empty($aColumnDimensions)) {
|
if (!empty($aColumnDimensions)) {
|
||||||
|
@ -250,7 +246,6 @@ class PHPExcel_ReferenceHelper
|
||||||
$pSheet->refreshColumnDimensions();
|
$pSheet->refreshColumnDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: row dimensions
|
// Update worksheet: row dimensions
|
||||||
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true);
|
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true);
|
||||||
if (!empty($aRowDimensions)) {
|
if (!empty($aRowDimensions)) {
|
||||||
|
@ -273,9 +268,11 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: breaks
|
// Update worksheet: breaks
|
||||||
$aBreaks = array_reverse($pSheet->getBreaks(), true);
|
$aBreaks = $pSheet->getBreaks();
|
||||||
|
($pNumCols > 0 || $pNumRows > 0) ?
|
||||||
|
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
|
||||||
|
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellSort'));
|
||||||
foreach ($aBreaks as $key => $value) {
|
foreach ($aBreaks as $key => $value) {
|
||||||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
||||||
if ($key != $newReference) {
|
if ($key != $newReference) {
|
||||||
|
@ -306,9 +303,11 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: data validations
|
// Update worksheet: data validations
|
||||||
$aDataValidationCollection = array_reverse($pSheet->getDataValidationCollection(), true);
|
$aDataValidationCollection = $pSheet->getDataValidationCollection();
|
||||||
|
($pNumCols > 0 || $pNumRows > 0) ?
|
||||||
|
uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
|
||||||
|
uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellSort'));
|
||||||
foreach ($aDataValidationCollection as $key => $value) {
|
foreach ($aDataValidationCollection as $key => $value) {
|
||||||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
||||||
if ($key != $newReference) {
|
if ($key != $newReference) {
|
||||||
|
@ -317,7 +316,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: merge cells
|
// Update worksheet: merge cells
|
||||||
$aMergeCells = $pSheet->getMergeCells();
|
$aMergeCells = $pSheet->getMergeCells();
|
||||||
$aNewMergeCells = array(); // the new array of all merge cells
|
$aNewMergeCells = array(); // the new array of all merge cells
|
||||||
|
@ -327,9 +325,11 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array
|
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: protected cells
|
// Update worksheet: protected cells
|
||||||
$aProtectedCells = array_reverse($pSheet->getProtectedCells(), true);
|
$aProtectedCells = $pSheet->getProtectedCells();
|
||||||
|
($pNumCols > 0 || $pNumRows > 0) ?
|
||||||
|
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
|
||||||
|
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellSort'));
|
||||||
foreach ($aProtectedCells as $key => $value) {
|
foreach ($aProtectedCells as $key => $value) {
|
||||||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
|
||||||
if ($key != $newReference) {
|
if ($key != $newReference) {
|
||||||
|
@ -338,7 +338,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: autofilter
|
// Update worksheet: autofilter
|
||||||
$autoFilter = $pSheet->getAutoFilter();
|
$autoFilter = $pSheet->getAutoFilter();
|
||||||
$autoFilterRange = $autoFilter->getRange();
|
$autoFilterRange = $autoFilter->getRange();
|
||||||
|
@ -397,19 +396,16 @@ class PHPExcel_ReferenceHelper
|
||||||
$pSheet->setAutoFilter( $this->updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows) );
|
$pSheet->setAutoFilter( $this->updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: freeze pane
|
// Update worksheet: freeze pane
|
||||||
if ($pSheet->getFreezePane() != '') {
|
if ($pSheet->getFreezePane() != '') {
|
||||||
$pSheet->freezePane( $this->updateCellReference($pSheet->getFreezePane(), $pBefore, $pNumCols, $pNumRows) );
|
$pSheet->freezePane( $this->updateCellReference($pSheet->getFreezePane(), $pBefore, $pNumCols, $pNumRows) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Page setup
|
// Page setup
|
||||||
if ($pSheet->getPageSetup()->isPrintAreaSet()) {
|
if ($pSheet->getPageSetup()->isPrintAreaSet()) {
|
||||||
$pSheet->getPageSetup()->setPrintArea( $this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows) );
|
$pSheet->getPageSetup()->setPrintArea( $this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update worksheet: drawings
|
// Update worksheet: drawings
|
||||||
$aDrawings = $pSheet->getDrawingCollection();
|
$aDrawings = $pSheet->getDrawingCollection();
|
||||||
foreach ($aDrawings as $objDrawing) {
|
foreach ($aDrawings as $objDrawing) {
|
||||||
|
@ -419,7 +415,6 @@ class PHPExcel_ReferenceHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update workbook: named ranges
|
// Update workbook: named ranges
|
||||||
if (count($pSheet->getParent()->getNamedRanges()) > 0) {
|
if (count($pSheet->getParent()->getNamedRanges()) > 0) {
|
||||||
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) {
|
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) {
|
||||||
|
|
Loading…
Reference in New Issue