You are here

function sheetnode_phpexcel_sheetnode_phpexcel_html2richtext in Sheetnode 6

Same name and namespace in other branches
  1. 5 modules/sheetnode_phpexcel/sheetnode_phpexcel.export.inc \sheetnode_phpexcel_sheetnode_phpexcel_html2richtext()
  2. 7.2 modules/sheetnode_phpexcel/sheetnode_phpexcel.export.inc \sheetnode_phpexcel_sheetnode_phpexcel_html2richtext()
  3. 7 modules/sheetnode_phpexcel/sheetnode_phpexcel.export.inc \sheetnode_phpexcel_sheetnode_phpexcel_html2richtext()

Implementation of hook_sheetnode_phpexcel_html2richtext.

Handles standard HTML tags and converts them to styling commands on the current rich-text run.

Parameters

$run PHPExcel_RichText_Run instance:

$cell PHPExcel_Cell instance:

$entry array entry of DOM as returned by TCPDF::getHtmlDomArray():

$converter Sheetnode_PHPExcel_HTML2RichText instance:

File

modules/sheetnode_phpexcel/sheetnode_phpexcel.export.inc, line 584

Code

function sheetnode_phpexcel_sheetnode_phpexcel_html2richtext($run, $cell, $entry, $converter) {

  // Set style based on tag.
  switch ($entry['value']) {
    case 'strong':
    case 'b':
      $run
        ->getFont()
        ->setBold(TRUE);
      break;
    case 'em':
    case 'i':
      $run
        ->getFont()
        ->setItalic(TRUE);
      break;
    case 'u':
      $run
        ->getFont()
        ->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
      break;
    case 'strike':
      $run
        ->getFont()
        ->setStrikethrough(TRUE);
      break;
    case 'sub':
      $run
        ->getFont()
        ->setSubScript(TRUE);
      break;
    case 'sup':
      $run
        ->getFont()
        ->setSuperScript(TRUE);
      break;
    case 'a':
      if (!empty($entry['attribute']['href'])) {
        $cell
          ->getHyperlink()
          ->setUrl($entry['attribute']['href']);
      }
      break;
  }

  // Set style based on tag attributes if any.
  // Set style base on CSS style if any.
  if (!empty($entry['style'])) {
    foreach ($entry['style'] as $key => $value) {
      switch ($key) {
        case 'color':
          $color = $converter
            ->convertHTMLColorToDec($value);
          $rgb = sprintf('%02X%02X%02X', $color['R'], $color['G'], $color['B']);
          $run
            ->getFont()
            ->getColor()
            ->setRGB($rgb);
          break;
        case 'font-family':
          $run
            ->getFont()
            ->setName($value);
          break;
        case 'font-size':
          $run
            ->getFont()
            ->setSize($converter
            ->getHTMLUnitToUnits($value, 1, 'pt', TRUE));
          break;
        case 'font-style':
          switch ($value) {
            case 'italic':
              $run
                ->getFont()
                ->setItalic(TRUE);
              break;
          }
          break;
        case 'text-decoration':
          switch ($value) {
            case 'underline':
              $run
                ->getFont()
                ->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
              break;
          }
          break;
        case 'font-weight':
          if ($value == 'bold' || $value == 'bolder' || $value >= 700) {
            $run
              ->getFont()
              ->setBold(TRUE);
          }
          break;
        case 'background-color':

          // TODO: Text runs don't support background colors.
          break;
      }
    }
  }
}