mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-22 21:36:05 +03:00
Improve sheet index error handling
Fix 'Undefined offset: -1' warning, thrown when worksheets could not be parsed and _activeSheetIndex equals -1.
This commit is contained in:
parent
280620a753
commit
fdfd36cc04
@ -461,10 +461,12 @@ class PHPExcel
|
|||||||
* Get active sheet
|
* Get active sheet
|
||||||
*
|
*
|
||||||
* @return PHPExcel_Worksheet
|
* @return PHPExcel_Worksheet
|
||||||
|
*
|
||||||
|
* @throws PHPExcel_Exception
|
||||||
*/
|
*/
|
||||||
public function getActiveSheet()
|
public function getActiveSheet()
|
||||||
{
|
{
|
||||||
return $this->_workSheetCollection[$this->_activeSheetIndex];
|
return $this->getSheet($this->_activeSheetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,16 +572,14 @@ class PHPExcel
|
|||||||
*/
|
*/
|
||||||
public function getSheet($pIndex = 0)
|
public function getSheet($pIndex = 0)
|
||||||
{
|
{
|
||||||
|
if (!isset($this->_workSheetCollection[$pIndex])) {
|
||||||
$numSheets = count($this->_workSheetCollection);
|
$numSheets = $this->getSheetCount();
|
||||||
|
|
||||||
if ($pIndex > $numSheets - 1) {
|
|
||||||
throw new PHPExcel_Exception(
|
throw new PHPExcel_Exception(
|
||||||
"Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
|
"Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}."
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return $this->_workSheetCollection[$pIndex];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->_workSheetCollection[$pIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -682,7 +682,7 @@ class PHPExcel
|
|||||||
*/
|
*/
|
||||||
public function setActiveSheetIndex($pIndex = 0)
|
public function setActiveSheetIndex($pIndex = 0)
|
||||||
{
|
{
|
||||||
$numSheets = count($this->_workSheetCollection);
|
$numSheets = count($this->_workSheetCollection);
|
||||||
|
|
||||||
if ($pIndex > $numSheets - 1) {
|
if ($pIndex > $numSheets - 1) {
|
||||||
throw new PHPExcel_Exception(
|
throw new PHPExcel_Exception(
|
||||||
|
Loading…
Reference in New Issue
Block a user