Skip to content

Commit

Permalink
Merge pull request PHPOffice#432 from driebit/fix-undefined-offset
Browse files Browse the repository at this point in the history
Improve sheet index error handling
  • Loading branch information
Progi1984 committed Sep 8, 2014
2 parents 280620a + fdfd36c commit b56bcb9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Classes/PHPExcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,12 @@ public function setSecurity(PHPExcel_DocumentSecurity $pValue)
* Get active sheet
*
* @return PHPExcel_Worksheet
*
* @throws PHPExcel_Exception
*/
public function getActiveSheet()
{
return $this->_workSheetCollection[$this->_activeSheetIndex];
return $this->getSheet($this->_activeSheetIndex);
}

/**
Expand Down Expand Up @@ -570,16 +572,14 @@ public function removeSheetByIndex($pIndex = 0)
*/
public function getSheet($pIndex = 0)
{

$numSheets = count($this->_workSheetCollection);

if ($pIndex > $numSheets - 1) {
if (!isset($this->_workSheetCollection[$pIndex])) {
$numSheets = $this->getSheetCount();
throw new PHPExcel_Exception(
"Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
);
} else {
return $this->_workSheetCollection[$pIndex];
"Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
);
}

return $this->_workSheetCollection[$pIndex];
}

/**
Expand Down Expand Up @@ -682,7 +682,7 @@ public function getActiveSheetIndex()
*/
public function setActiveSheetIndex($pIndex = 0)
{
$numSheets = count($this->_workSheetCollection);
$numSheets = count($this->_workSheetCollection);

if ($pIndex > $numSheets - 1) {
throw new PHPExcel_Exception(
Expand Down

0 comments on commit b56bcb9

Please sign in to comment.