Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Commit

Permalink
Additional work on GH-161 for Breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Baker committed Apr 23, 2013
1 parent 15bfe6b commit db1fcd5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
40 changes: 24 additions & 16 deletions Classes/PHPExcel/ReferenceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ public static function getInstance() {
protected function __construct() {
}

private function cellSort($a, $b) {
public static function columnSort($a, $b) {
return strcasecmp(strlen($a) . $a, strlen($b) . $b);
}

public static function columnReverseSort($a, $b) {
return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b);
}

public static function cellSort($a, $b) {
list($ac,$ar) = sscanf($a,'%[A-Z]%d');
list($bc,$br) = sscanf($b,'%[A-Z]%d');

Expand All @@ -78,7 +86,7 @@ private function cellSort($a, $b) {
return ($ar < $br) ? -1 : 1;
}

private function cellReverseSort($a, $b) {
public static function cellReverseSort($a, $b) {
list($ac,$ar) = sscanf($a,'%[A-Z]%d');
list($bc,$br) = sscanf($b,'%[A-Z]%d');

Expand Down Expand Up @@ -270,14 +278,14 @@ public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, P

// Update worksheet: breaks
$aBreaks = $pSheet->getBreaks();
($pNumCols > 0 || $pNumRows > 0) ?
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellSort'));
($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) {
$pSheet->setBreak( $newReference, $value );
$pSheet->setBreak( $key, PHPExcel_Worksheet::BREAK_NONE );
$pSheet->setBreak($newReference, $value)
->setBreak($key, PHPExcel_Worksheet::BREAK_NONE);
}
}

Expand All @@ -292,9 +300,9 @@ public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, P

// Update worksheet: hyperlinks
$aHyperlinkCollection = $pSheet->getHyperlinkCollection();
($pNumCols > 0 || $pNumRows > 0) ?
uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellSort'));
($pNumCols > 0 || $pNumRows > 0) ?
uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellSort'));
foreach ($aHyperlinkCollection as $key => $value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) {
Expand All @@ -305,9 +313,9 @@ public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, P

// Update worksheet: data validations
$aDataValidationCollection = $pSheet->getDataValidationCollection();
($pNumCols > 0 || $pNumRows > 0) ?
uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellSort'));
($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) {
Expand All @@ -327,9 +335,9 @@ public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, P

// Update worksheet: protected cells
$aProtectedCells = $pSheet->getProtectedCells();
($pNumCols > 0 || $pNumRows > 0) ?
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellReverseSort')) :
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellSort'));
($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) {
Expand Down
14 changes: 10 additions & 4 deletions Classes/PHPExcel/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,13 @@ public function setBreak($pCell = 'A1', $pBreak = PHPExcel_Worksheet::BREAK_NONE
$pCell = strtoupper($pCell);

if ($pCell != '') {
$this->_breaks[$pCell] = $pBreak;
if ($pBreak == PHPExcel_Worksheet::BREAK_NONE) {
if (isset($this->_breaks[$pCell])) {
unset($this->_breaks[$pCell]);
}
} else {
$this->_breaks[$pCell] = $pBreak;
}
} else {
throw new PHPExcel_Exception('No cell coordinate specified.');
}
Expand Down Expand Up @@ -2432,9 +2438,9 @@ public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormul
if ($formatData) {
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
$returnValue[$rRef][$cRef],
($style->getNumberFormat()) ?
$style->getNumberFormat()->getFormatCode() :
$returnValue[$rRef][$cRef],
($style->getNumberFormat()) ?
$style->getNumberFormat()->getFormatCode() :
PHPExcel_Style_NumberFormat::FORMAT_GENERAL
);
}
Expand Down

0 comments on commit db1fcd5

Please sign in to comment.