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;