fillType = null; } $this->startColor = new Color(Color::COLOR_WHITE, $isSupervisor, $isConditional); $this->endColor = new Color(Color::COLOR_BLACK, $isSupervisor, $isConditional); // bind parent if we are a supervisor if ($isSupervisor) { $this->startColor->bindParent($this, 'startColor'); $this->endColor->bindParent($this, 'endColor'); } } /** * Get the shared style component for the currently active cell in currently active sheet. * Only used for style supervisor. * * @return Fill */ public function getSharedComponent() { return $this->parent->getSharedComponent()->getFill(); } /** * Build style array from subcomponents. * * @param array $array * * @return array */ public function getStyleArray($array) { return ['fill' => $array]; } /** * Apply styles from array. * * * $spreadsheet->getActiveSheet()->getStyle('B2')->getFill()->applyFromArray( * array( * 'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR, * 'rotation' => 0, * 'startcolor' => array( * 'rgb' => '000000' * ), * 'endcolor' => array( * 'argb' => 'FFFFFFFF' * ) * ) * ); * * * @param array $pStyles Array containing style information * * @throws \PhpOffice\PhpSpreadsheet\Exception * * @return Fill */ public function applyFromArray($pStyles = null) { if (is_array($pStyles)) { if ($this->isSupervisor) { $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); } else { if (isset($pStyles['type'])) { $this->setFillType($pStyles['type']); } if (isset($pStyles['rotation'])) { $this->setRotation($pStyles['rotation']); } if (isset($pStyles['startcolor'])) { $this->getStartColor()->applyFromArray($pStyles['startcolor']); } if (isset($pStyles['endcolor'])) { $this->getEndColor()->applyFromArray($pStyles['endcolor']); } if (isset($pStyles['color'])) { $this->getStartColor()->applyFromArray($pStyles['color']); } } } else { throw new \PhpOffice\PhpSpreadsheet\Exception('Invalid style array passed.'); } return $this; } /** * Get Fill Type. * * @return string */ public function getFillType() { if ($this->isSupervisor) { return $this->getSharedComponent()->getFillType(); } return $this->fillType; } /** * Set Fill Type. * * @param string $pValue Fill type * * @return Fill */ public function setFillType($pValue = self::FILL_NONE) { if ($this->isSupervisor) { $styleArray = $this->getStyleArray(['type' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->fillType = $pValue; } return $this; } /** * Get Rotation. * * @return float */ public function getRotation() { if ($this->isSupervisor) { return $this->getSharedComponent()->getRotation(); } return $this->rotation; } /** * Set Rotation. * * @param float $pValue * * @return Fill */ public function setRotation($pValue = 0) { if ($this->isSupervisor) { $styleArray = $this->getStyleArray(['rotation' => $pValue]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->rotation = $pValue; } return $this; } /** * Get Start Color. * * @return Color */ public function getStartColor() { return $this->startColor; } /** * Set Start Color. * * @param Color $pValue * * @throws \PhpOffice\PhpSpreadsheet\Exception * * @return Fill */ public function setStartColor(Color $pValue = null) { // make sure parameter is a real color and not a supervisor $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; if ($this->isSupervisor) { $styleArray = $this->getStartColor()->getStyleArray(['argb' => $color->getARGB()]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->startColor = $color; } return $this; } /** * Get End Color. * * @return Color */ public function getEndColor() { return $this->endColor; } /** * Set End Color. * * @param Color $pValue * * @throws \PhpOffice\PhpSpreadsheet\Exception * * @return Fill */ public function setEndColor(Color $pValue = null) { // make sure parameter is a real color and not a supervisor $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue; if ($this->isSupervisor) { $styleArray = $this->getEndColor()->getStyleArray(['argb' => $color->getARGB()]); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); } else { $this->endColor = $color; } return $this; } /** * Get hash code. * * @return string Hash code */ public function getHashCode() { if ($this->isSupervisor) { return $this->getSharedComponent()->getHashCode(); } return md5( $this->getFillType() . $this->getRotation() . $this->getStartColor()->getHashCode() . $this->getEndColor()->getHashCode() . __CLASS__ ); } }