Additional work on GH-161 - Fix: Hyperlinks break when removing rows

This commit is contained in:
Mark Baker 2013-04-21 16:03:25 +01:00
parent ab01a6c6dc
commit 097ae1706e
1 changed files with 14 additions and 19 deletions

View File

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