You are here

public function PHPExcel::addSheet in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel.php \PHPExcel::addSheet()

Add sheet

Parameters

PHPExcel_Worksheet $pSheet:

int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last):

Return value

PHPExcel_Worksheet

Throws

PHPExcel_Exception

2 calls to PHPExcel::addSheet()
PHPExcel::addExternalSheet in vendor/phpoffice/phpexcel/Classes/PHPExcel.php
Add external sheet
PHPExcel::createSheet in vendor/phpoffice/phpexcel/Classes/PHPExcel.php
Create sheet and add it to this workbook

File

vendor/phpoffice/phpexcel/Classes/PHPExcel.php, line 505

Class

PHPExcel
PHPExcel

Code

public function addSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = NULL) {
  if ($this
    ->sheetNameExists($pSheet
    ->getTitle())) {
    throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first.");
  }
  if ($iSheetIndex === NULL) {
    if ($this->_activeSheetIndex < 0) {
      $this->_activeSheetIndex = 0;
    }
    $this->_workSheetCollection[] = $pSheet;
  }
  else {

    // Insert the sheet at the requested index
    array_splice($this->_workSheetCollection, $iSheetIndex, 0, array(
      $pSheet,
    ));

    // Adjust active sheet index if necessary
    if ($this->_activeSheetIndex >= $iSheetIndex) {
      ++$this->_activeSheetIndex;
    }
  }
  if ($pSheet
    ->getParent() === null) {
    $pSheet
      ->rebindParent($this);
  }
  return $pSheet;
}