From ee309f6e930885c20014000f2e7dfa871314485c Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 28 Dec 2014 19:08:33 +0000 Subject: [PATCH] Fix initialisation of html to Rich Text helper, and provide additional examples --- Classes/PHPExcel/Helper/HTML.php | 11 +++++++++++ Examples/42richText.php | 30 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Classes/PHPExcel/Helper/HTML.php b/Classes/PHPExcel/Helper/HTML.php index 1cde91cd..a3e04051 100644 --- a/Classes/PHPExcel/Helper/HTML.php +++ b/Classes/PHPExcel/Helper/HTML.php @@ -573,7 +573,18 @@ class PHPExcel_Helper_HTML protected $richTextObject; + protected function initialise() { + $this->face = $this->size = $this->color = null; + $this->bold = $this->italic = $this->underline = $this->superscript = $this->subscript = $this->strikethrough = false; + + $this->stack = array(); + + $this->stringData = ''; + } + public function toRichTextObject($html) { + $this->initialise(); + // Create a new DOM object $dom = new domDocument; // Load the HTML file into the DOM object diff --git a/Examples/42richText.php b/Examples/42richText.php index cfaf09d9..00162723 100644 --- a/Examples/42richText.php +++ b/Examples/42richText.php @@ -55,21 +55,31 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") // Add some data echo date('H:i:s') , " Add some data" , EOL; -$html=' +$html1='

My very first example of rich text
generated from html markup

- + This block contains an italicized word; while this block uses an underline.

-

-I want to eat steakpizza. +

+I want to eat healthy foodpizza. '; +$html2='

+ + 100°C is a hot temperature + +
+ + 10°F is cold + +

'; + $wizard = new PHPExcel_Helper_HTML; -$richText = $wizard->toRichTextObject($html); +$richText = $wizard->toRichTextObject($html1); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', $richText); @@ -80,6 +90,16 @@ $objPHPExcel->getActiveSheet()->getStyle('A1') ->getAlignment() ->setWrapText(true); +$richText = $wizard->toRichTextObject($html2); + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A2', $richText); + +$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A2') + ->getAlignment() + ->setWrapText(true); + // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL;