original_string: public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null)
      {
          if ($this->sheetNameExists($pSheet->getTitle())) {
              throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
          }
  
          // count how many cellXfs there are in this workbook currently, we will need this below
          $countCellXfs = count($this->cellXfCollection);
  
          // copy all the shared cellXfs from the external workbook and append them to the current
          foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
              $this->addCellXf(clone $cellXf);
          }
  
          // move sheet to this workbook
          $pSheet->rebindParent($this);
  
          // update the cellXfs
          foreach ($pSheet->getCellCollection(false) as $cellID) {
              $cell = $pSheet->getCell($cellID);
              $cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
          }
  
          return $this->addSheet($pSheet, $iSheetIndex);
      }
code: public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null)
      {
          if ($this->sheetNameExists($pSheet->getTitle())) {
              throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
          }
  
          // count how many cellXfs there are in this workbook currently, we will need this below
          $countCellXfs = count($this->cellXfCollection);
  
          // copy all the shared cellXfs from the external workbook and append them to the current
          foreach ($pSheet->getParent()->getCellXfCollection() as $cellXf) {
              $this->addCellXf(clone $cellXf);
          }
  
          // move sheet to this workbook
          $pSheet->rebindParent($this);
  
          // update the cellXfs
          foreach ($pSheet->getCellCollection(false) as $cellID) {
              $cell = $pSheet->getCell($cellID);
              $cell->setXfIndex($cell->getXfIndex() + $countCellXfs);
          }
  
          return $this->addSheet($pSheet, $iSheetIndex);
      }
code_tokens: public function addExternalSheet ( PHPExcel_Worksheet $ pSheet , $ iSheetIndex = null ) { if ( $ this -> sheetNameExists ( $ pSheet -> getTitle ( ) ) ) { throw new PHPExcel_Exception ( "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first." ) ; } // count how many cellXfs there are in this workbook currently, we will need this below $ countCellXfs = count ( $ this -> cellXfCollection ) ; // copy all the shared cellXfs from the external workbook and append them to the current foreach ( $ pSheet -> getParent ( ) -> getCellXfCollection ( ) as $ cellXf ) { $ this -> addCellXf ( clone $ cellXf ) ; } // move sheet to this workbook $ pSheet -> rebindParent ( $ this ) ; // update the cellXfs foreach ( $ pSheet -> getCellCollection ( false ) as $ cellID ) { $ cell = $ pSheet -> getCell ( $ cellID ) ; $ cell -> setXfIndex ( $ cell -> getXfIndex ( ) + $ countCellXfs ) ; } return $ this -> addSheet ( $ pSheet , $ iSheetIndex ) ; }
docstring: Add external sheet
  
  @param  PHPExcel_Worksheet $pSheet External sheet to add
  @param  int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
  @throws PHPExcel_Exception
  @return PHPExcel_Worksheet
docstring_tokens: Add external sheet