You are here

public function PHPExcel_Worksheet_BaseDrawing::setWorksheet in Loft Data Grids 7.2

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

Set Worksheet

Parameters

PHPExcel_Worksheet $pValue:

bool $pOverrideOld If a Worksheet has already been assigned, overwrite it and remove image from old Worksheet?:

Return value

PHPExcel_Worksheet_BaseDrawing

Throws

PHPExcel_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/BaseDrawing.php, line 218

Class

PHPExcel_Worksheet_BaseDrawing
PHPExcel_Worksheet_BaseDrawing

Code

public function setWorksheet(PHPExcel_Worksheet $pValue = null, $pOverrideOld = false) {
  if (is_null($this->_worksheet)) {

    // Add drawing to PHPExcel_Worksheet
    $this->_worksheet = $pValue;
    $this->_worksheet
      ->getCell($this->_coordinates);
    $this->_worksheet
      ->getDrawingCollection()
      ->append($this);
  }
  else {
    if ($pOverrideOld) {

      // Remove drawing from old PHPExcel_Worksheet
      $iterator = $this->_worksheet
        ->getDrawingCollection()
        ->getIterator();
      while ($iterator
        ->valid()) {
        if ($iterator
          ->current()
          ->getHashCode() == $this
          ->getHashCode()) {
          $this->_worksheet
            ->getDrawingCollection()
            ->offsetUnset($iterator
            ->key());
          $this->_worksheet = null;
          break;
        }
      }

      // Set new PHPExcel_Worksheet
      $this
        ->setWorksheet($pValue);
    }
    else {
      throw new PHPExcel_Exception("A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet.");
    }
  }
  return $this;
}