Fix initialisation of html to Rich Text helper, and provide additional examples

This commit is contained in:
MarkBaker 2014-12-28 19:08:33 +00:00
parent 7a45239672
commit ee309f6e93
2 changed files with 36 additions and 5 deletions

View File

@ -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

View File

@ -55,21 +55,31 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data
echo date('H:i:s') , " Add some data" , EOL;
$html='<font color="#0000ff">
$html1='<font color="#0000ff">
<h1 align="center">My very first example of rich text<br />generated from html markup</h1>
<p>
<font size="12" COLOR="rgb(0,255,128)">
<font size="14" COLOR="rgb(0,255,128)">
<b>This block</b> contains an <i>italicized</i> word;
while this block uses an <u>underline</u>.
</font>
</p>
<p align="right"><font size="8" color="red">
I want to eat <ins><del>steak</del><strong>pizza</strong></ins>.
<p align="right"><font size="9" color="red">
I want to eat <ins><del>healthy food</del><strong>pizza</strong></ins>.
</font>
';
$html2='<p>
<font color="#ff0000">
100&deg;C is a hot temperature
</font>
<br>
<font color="#0080ff">
10&deg;F is cold
</font>
</p>';
$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;