You are here

public function PHPExcel_Writer_HTML::formatColor in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php \PHPExcel_Writer_HTML::formatColor()

* Add color to formatted string as inline style * *

Parameters

string $pValue Plain formatted value without color: * @param string $pFormat Format code * @return string

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php, line 1411

Class

PHPExcel_Writer_HTML
PHPExcel_Writer_HTML

Code

public function formatColor($pValue, $pFormat) {

  // Color information, e.g. [Red] is always at the beginning
  $color = null;

  // initialize
  $matches = array();
  $color_regex = '/^\\[[a-zA-Z]+\\]/';
  if (preg_match($color_regex, $pFormat, $matches)) {
    $color = str_replace('[', '', $matches[0]);
    $color = str_replace(']', '', $color);
    $color = strtolower($color);
  }

  // convert to PCDATA
  $value = htmlspecialchars($pValue);

  // color span tag
  if ($color !== null) {
    $value = '<span style="color:' . $color . '">' . $value . '</span>';
  }
  return $value;
}