You are here

public function Sheetnode_PHPExcel_HTML2RichText::convert in Sheetnode 7.2

Same name and namespace in other branches
  1. 5 modules/sheetnode_phpexcel/sheetnode_phpexcel.export.inc \Sheetnode_PHPExcel_HTML2RichText::convert()
  2. 6 modules/sheetnode_phpexcel/html2richtext.inc \Sheetnode_PHPExcel_HTML2RichText::convert()
  3. 7 modules/sheetnode_phpexcel/html2richtext.inc \Sheetnode_PHPExcel_HTML2RichText::convert()

File

modules/sheetnode_phpexcel/html2richtext.inc, line 14
Class to convert an HTML fragment to a fully-parsed array of styles. Uses TCDPF which is included in PHPExcel.

Class

Sheetnode_PHPExcel_HTML2RichText
@file Class to convert an HTML fragment to a fully-parsed array of styles. Uses TCDPF which is included in PHPExcel.

Code

public function convert($cell) {
  $dom = $this
    ->getHtmlDomArray($this->html);
  if (empty($dom)) {
    return FALSE;
  }
  $rtf = new PHPExcel_RichText();
  $run = $rtf
    ->createTextRun();
  foreach ($dom as $entry) {
    if ($entry['tag']) {

      // HTML tag
      if (!$entry['opening']) {
        continue;
      }

      // Defer the work to third-party implementations.
      module_invoke_all('sheetnode_phpexcel_html2richtext', $run, $cell, $entry, $this);
    }
    else {

      // text
      if (empty($entry['value'])) {
        continue;
      }
      $run
        ->setText($entry['value']);
      $run = $rtf
        ->createTextRun();
    }
    drupal_alter('sheetnode_phpexcel_html2richtext', $run, $cell, $entry, $this);
  }
  return $rtf;
}