Read Cell with custom font and line return ?

Topics: Developer Forum
Sep 14, 2012 at 12:04 PM

Hi,

I have an XLSX file with a special cell and i want to convert it to HTML. In this cell i have some text with special format, i have line return (ALT + Enter), i have bold, underline and italic...

How can i convert this cell with PHPExcel ?

I tried something like this :

 

$objRichText = new PHPExcel_RichText($objWorksheet->getCellByColumnAndRow(1, $l));
			$elements = $objRichText->getRichTextElements();
			$s = "";

			foreach ($elements as $elt) {
			
				if ($elt->getText() != ""){
					$txt = $elt->getText();
					if ($elt->getFont()->getBold()){
						$txt = "<strong>" . $txt . "</strong>";
					}
					if ($elt->getFont()->getItalic()){
						$txt = "<i>" . $txt . "</i>";
					}
					if ($elt->getFont()->getUnderline()){
						$txt = "<u>" . $txt . "</u>";
					}
					$s .= $txt;
				}
			}
			$s = str_replace("\r\n","<br/>", $s);

 

But it's doesn't work very well :

<u><strong>bold
iltalic
underline</strong></u>
<u><strong>bold
iltalic
underline</strong></u>

Looks like my cell is not splitted into 3 elements...

It's my code or it's not working ?

 

Thanks

Guldil