You are here

public function PHPExcel_Writer_Excel5_Workbook::addXfWriter in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php \PHPExcel_Writer_Excel5_Workbook::addXfWriter()

* Add a new XF writer * *

Parameters

PHPExcel_Style: * @param boolean Is it a style XF? * @return int Index to XF record

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Workbook.php, line 253

Class

PHPExcel_Writer_Excel5_Workbook
PHPExcel_Writer_Excel5_Workbook

Code

public function addXfWriter($style, $isStyleXf = false) {
  $xfWriter = new PHPExcel_Writer_Excel5_Xf($style);
  $xfWriter
    ->setIsStyleXf($isStyleXf);

  // Add the font if not already added
  $fontIndex = $this
    ->_addFont($style
    ->getFont());

  // Assign the font index to the xf record
  $xfWriter
    ->setFontIndex($fontIndex);

  // Background colors, best to treat these after the font so black will come after white in custom palette
  $xfWriter
    ->setFgColor($this
    ->_addColor($style
    ->getFill()
    ->getStartColor()
    ->getRGB()));
  $xfWriter
    ->setBgColor($this
    ->_addColor($style
    ->getFill()
    ->getEndColor()
    ->getRGB()));
  $xfWriter
    ->setBottomColor($this
    ->_addColor($style
    ->getBorders()
    ->getBottom()
    ->getColor()
    ->getRGB()));
  $xfWriter
    ->setTopColor($this
    ->_addColor($style
    ->getBorders()
    ->getTop()
    ->getColor()
    ->getRGB()));
  $xfWriter
    ->setRightColor($this
    ->_addColor($style
    ->getBorders()
    ->getRight()
    ->getColor()
    ->getRGB()));
  $xfWriter
    ->setLeftColor($this
    ->_addColor($style
    ->getBorders()
    ->getLeft()
    ->getColor()
    ->getRGB()));
  $xfWriter
    ->setDiagColor($this
    ->_addColor($style
    ->getBorders()
    ->getDiagonal()
    ->getColor()
    ->getRGB()));

  // Add the number format if it is not a built-in one and not already added
  if ($style
    ->getNumberFormat()
    ->getBuiltInFormatCode() === false) {
    $numberFormatHashCode = $style
      ->getNumberFormat()
      ->getHashCode();
    if (isset($this->_addedNumberFormats[$numberFormatHashCode])) {
      $numberFormatIndex = $this->_addedNumberFormats[$numberFormatHashCode];
    }
    else {
      $numberFormatIndex = 164 + count($this->_numberFormats);
      $this->_numberFormats[$numberFormatIndex] = $style
        ->getNumberFormat();
      $this->_addedNumberFormats[$numberFormatHashCode] = $numberFormatIndex;
    }
  }
  else {
    $numberFormatIndex = (int) $style
      ->getNumberFormat()
      ->getBuiltInFormatCode();
  }

  // Assign the number format index to xf record
  $xfWriter
    ->setNumberFormatIndex($numberFormatIndex);
  $this->_xfWriters[] = $xfWriter;
  $xfIndex = count($this->_xfWriters) - 1;
  return $xfIndex;
}