You are here

private static function PHPExcel_Reader_Excel2007::_readStyle in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php \PHPExcel_Reader_Excel2007::_readStyle()
1 call to PHPExcel_Reader_Excel2007::_readStyle()
PHPExcel_Reader_Excel2007::load in vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php
* Loads PHPExcel from file * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php, line 1789

Class

PHPExcel_Reader_Excel2007
PHPExcel_Reader_Excel2007

Code

private static function _readStyle($docStyle, $style) {

  // format code
  //		if (isset($style->numFmt)) {
  //			if (isset($style->numFmt['formatCode'])) {
  //				$docStyle->getNumberFormat()->setFormatCode((string) $style->numFmt['formatCode']);
  //			} else {
  $docStyle
    ->getNumberFormat()
    ->setFormatCode($style->numFmt);

  //			}
  //		}
  // font
  if (isset($style->font)) {
    $docStyle
      ->getFont()
      ->setName((string) $style->font->name["val"]);
    $docStyle
      ->getFont()
      ->setSize((string) $style->font->sz["val"]);
    if (isset($style->font->b)) {
      $docStyle
        ->getFont()
        ->setBold(!isset($style->font->b["val"]) || self::boolean((string) $style->font->b["val"]));
    }
    if (isset($style->font->i)) {
      $docStyle
        ->getFont()
        ->setItalic(!isset($style->font->i["val"]) || self::boolean((string) $style->font->i["val"]));
    }
    if (isset($style->font->strike)) {
      $docStyle
        ->getFont()
        ->setStrikethrough(!isset($style->font->strike["val"]) || self::boolean((string) $style->font->strike["val"]));
    }
    $docStyle
      ->getFont()
      ->getColor()
      ->setARGB(self::_readColor($style->font->color));
    if (isset($style->font->u) && !isset($style->font->u["val"])) {
      $docStyle
        ->getFont()
        ->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
    }
    else {
      if (isset($style->font->u) && isset($style->font->u["val"])) {
        $docStyle
          ->getFont()
          ->setUnderline((string) $style->font->u["val"]);
      }
    }
    if (isset($style->font->vertAlign) && isset($style->font->vertAlign["val"])) {
      $vertAlign = strtolower((string) $style->font->vertAlign["val"]);
      if ($vertAlign == 'superscript') {
        $docStyle
          ->getFont()
          ->setSuperScript(true);
      }
      if ($vertAlign == 'subscript') {
        $docStyle
          ->getFont()
          ->setSubScript(true);
      }
    }
  }

  // fill
  if (isset($style->fill)) {
    if ($style->fill->gradientFill) {
      $gradientFill = $style->fill->gradientFill[0];
      if (!empty($gradientFill["type"])) {
        $docStyle
          ->getFill()
          ->setFillType((string) $gradientFill["type"]);
      }
      $docStyle
        ->getFill()
        ->setRotation(floatval($gradientFill["degree"]));
      $gradientFill
        ->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
      $docStyle
        ->getFill()
        ->getStartColor()
        ->setARGB(self::_readColor(self::array_item($gradientFill
        ->xpath("sml:stop[@position=0]"))->color));
      $docStyle
        ->getFill()
        ->getEndColor()
        ->setARGB(self::_readColor(self::array_item($gradientFill
        ->xpath("sml:stop[@position=1]"))->color));
    }
    elseif ($style->fill->patternFill) {
      $patternType = (string) $style->fill->patternFill["patternType"] != '' ? (string) $style->fill->patternFill["patternType"] : 'solid';
      $docStyle
        ->getFill()
        ->setFillType($patternType);
      if ($style->fill->patternFill->fgColor) {
        $docStyle
          ->getFill()
          ->getStartColor()
          ->setARGB(self::_readColor($style->fill->patternFill->fgColor, true));
      }
      else {
        $docStyle
          ->getFill()
          ->getStartColor()
          ->setARGB('FF000000');
      }
      if ($style->fill->patternFill->bgColor) {
        $docStyle
          ->getFill()
          ->getEndColor()
          ->setARGB(self::_readColor($style->fill->patternFill->bgColor, true));
      }
    }
  }

  // border
  if (isset($style->border)) {
    $diagonalUp = self::boolean((string) $style->border["diagonalUp"]);
    $diagonalDown = self::boolean((string) $style->border["diagonalDown"]);
    if (!$diagonalUp && !$diagonalDown) {
      $docStyle
        ->getBorders()
        ->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE);
    }
    elseif ($diagonalUp && !$diagonalDown) {
      $docStyle
        ->getBorders()
        ->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
    }
    elseif (!$diagonalUp && $diagonalDown) {
      $docStyle
        ->getBorders()
        ->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
    }
    else {
      $docStyle
        ->getBorders()
        ->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH);
    }
    self::_readBorder($docStyle
      ->getBorders()
      ->getLeft(), $style->border->left);
    self::_readBorder($docStyle
      ->getBorders()
      ->getRight(), $style->border->right);
    self::_readBorder($docStyle
      ->getBorders()
      ->getTop(), $style->border->top);
    self::_readBorder($docStyle
      ->getBorders()
      ->getBottom(), $style->border->bottom);
    self::_readBorder($docStyle
      ->getBorders()
      ->getDiagonal(), $style->border->diagonal);
  }

  // alignment
  if (isset($style->alignment)) {
    $docStyle
      ->getAlignment()
      ->setHorizontal((string) $style->alignment["horizontal"]);
    $docStyle
      ->getAlignment()
      ->setVertical((string) $style->alignment["vertical"]);
    $textRotation = 0;
    if ((int) $style->alignment["textRotation"] <= 90) {
      $textRotation = (int) $style->alignment["textRotation"];
    }
    else {
      if ((int) $style->alignment["textRotation"] > 90) {
        $textRotation = 90 - (int) $style->alignment["textRotation"];
      }
    }
    $docStyle
      ->getAlignment()
      ->setTextRotation(intval($textRotation));
    $docStyle
      ->getAlignment()
      ->setWrapText(self::boolean((string) $style->alignment["wrapText"]));
    $docStyle
      ->getAlignment()
      ->setShrinkToFit(self::boolean((string) $style->alignment["shrinkToFit"]));
    $docStyle
      ->getAlignment()
      ->setIndent(intval((string) $style->alignment["indent"]) > 0 ? intval((string) $style->alignment["indent"]) : 0);
    $docStyle
      ->getAlignment()
      ->setReadorder(intval((string) $style->alignment["readingOrder"]) > 0 ? intval((string) $style->alignment["readingOrder"]) : 0);
  }

  // protection
  if (isset($style->protection)) {
    if (isset($style->protection['locked'])) {
      if (self::boolean((string) $style->protection['locked'])) {
        $docStyle
          ->getProtection()
          ->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
      }
      else {
        $docStyle
          ->getProtection()
          ->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
      }
    }
    if (isset($style->protection['hidden'])) {
      if (self::boolean((string) $style->protection['hidden'])) {
        $docStyle
          ->getProtection()
          ->setHidden(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
      }
      else {
        $docStyle
          ->getProtection()
          ->setHidden(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
      }
    }
  }

  // top-level style settings
  if (isset($style->quotePrefix)) {
    $docStyle
      ->setQuotePrefix($style->quotePrefix);
  }
}