You are here

function PHPExcel_Writer_Excel5_Xf::writeXf in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Xf.php \PHPExcel_Writer_Excel5_Xf::writeXf()

* Generate an Excel BIFF XF record (style or cell). * *

Return value

string The XF record

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Xf.php, line 169

Class

PHPExcel_Writer_Excel5_Xf
PHPExcel_Writer_Excel5_Xf

Code

function writeXf() {

  // Set the type of the XF record and some of the attributes.
  if ($this->_isStyleXf) {
    $style = 0xfff5;
  }
  else {
    $style = self::_mapLocked($this->_style
      ->getProtection()
      ->getLocked());
    $style |= self::_mapHidden($this->_style
      ->getProtection()
      ->getHidden()) << 1;
  }

  // Flags to indicate if attributes have been set.
  $atr_num = $this->_numberFormatIndex != 0 ? 1 : 0;
  $atr_fnt = $this->_fontIndex != 0 ? 1 : 0;
  $atr_alc = (int) $this->_style
    ->getAlignment()
    ->getWrapText() ? 1 : 0;
  $atr_bdr = self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getBottom()
    ->getBorderStyle()) || self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getTop()
    ->getBorderStyle()) || self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getLeft()
    ->getBorderStyle()) || self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getRight()
    ->getBorderStyle()) ? 1 : 0;
  $atr_pat = $this->_fg_color != 0x40 || $this->_bg_color != 0x41 || self::_mapFillType($this->_style
    ->getFill()
    ->getFillType()) ? 1 : 0;
  $atr_prot = self::_mapLocked($this->_style
    ->getProtection()
    ->getLocked()) | self::_mapHidden($this->_style
    ->getProtection()
    ->getHidden());

  // Zero the default border colour if the border has not been set.
  if (self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getBottom()
    ->getBorderStyle()) == 0) {
    $this->_bottom_color = 0;
  }
  if (self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getTop()
    ->getBorderStyle()) == 0) {
    $this->_top_color = 0;
  }
  if (self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getRight()
    ->getBorderStyle()) == 0) {
    $this->_right_color = 0;
  }
  if (self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getLeft()
    ->getBorderStyle()) == 0) {
    $this->_left_color = 0;
  }
  if (self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getDiagonal()
    ->getBorderStyle()) == 0) {
    $this->_diag_color = 0;
  }
  $record = 0xe0;

  // Record identifier
  $length = 0x14;

  // Number of bytes to follow
  $ifnt = $this->_fontIndex;

  // Index to FONT record
  $ifmt = $this->_numberFormatIndex;

  // Index to FORMAT record
  $align = $this
    ->_mapHAlign($this->_style
    ->getAlignment()
    ->getHorizontal());

  // Alignment
  $align |= (int) $this->_style
    ->getAlignment()
    ->getWrapText() << 3;
  $align |= self::_mapVAlign($this->_style
    ->getAlignment()
    ->getVertical()) << 4;
  $align |= $this->_text_justlast << 7;
  $used_attrib = $atr_num << 2;
  $used_attrib |= $atr_fnt << 3;
  $used_attrib |= $atr_alc << 4;
  $used_attrib |= $atr_bdr << 5;
  $used_attrib |= $atr_pat << 6;
  $used_attrib |= $atr_prot << 7;
  $icv = $this->_fg_color;

  // fg and bg pattern colors
  $icv |= $this->_bg_color << 7;
  $border1 = self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getLeft()
    ->getBorderStyle());

  // Border line style and color
  $border1 |= self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getRight()
    ->getBorderStyle()) << 4;
  $border1 |= self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getTop()
    ->getBorderStyle()) << 8;
  $border1 |= self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getBottom()
    ->getBorderStyle()) << 12;
  $border1 |= $this->_left_color << 16;
  $border1 |= $this->_right_color << 23;
  $diagonalDirection = $this->_style
    ->getBorders()
    ->getDiagonalDirection();
  $diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN;
  $diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH || $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP;
  $border1 |= $diag_tl_to_rb << 30;
  $border1 |= $diag_tr_to_lb << 31;
  $border2 = $this->_top_color;

  // Border color
  $border2 |= $this->_bottom_color << 7;
  $border2 |= $this->_diag_color << 14;
  $border2 |= self::_mapBorderStyle($this->_style
    ->getBorders()
    ->getDiagonal()
    ->getBorderStyle()) << 21;
  $border2 |= self::_mapFillType($this->_style
    ->getFill()
    ->getFillType()) << 26;
  $header = pack("vv", $record, $length);

  //BIFF8 options: identation, shrinkToFit and  text direction
  $biff8_options = $this->_style
    ->getAlignment()
    ->getIndent();
  $biff8_options |= (int) $this->_style
    ->getAlignment()
    ->getShrinkToFit() << 4;
  $data = pack("vvvC", $ifnt, $ifmt, $style, $align);
  $data .= pack("CCC", self::_mapTextRotation($this->_style
    ->getAlignment()
    ->getTextRotation()), $biff8_options, $used_attrib);
  $data .= pack("VVv", $border1, $border2, $icv);
  return $header . $data;
}