jamcoder
jamcoder

Reputation: 569

PHPExcel Render html tags inside cell not as plain text

Is the current PHPExcel can now format HTML tags inside excel cell? This is like question here

I have a table from database that has field that contains string with html tags

i.e. < b > hello < / b >

and I want it to output in excel not as a plain text but something like this hello

Is there any php to excel library that can do this? any idea? thanks in advance

Upvotes: 2

Views: 8884

Answers (2)

Mark Baker
Mark Baker

Reputation: 212412

No! PHPExcel doesn't have any built-in logic to do this; and nor does any other library that I'm aware of.

You'd need to write some code yourself to handle the conversion from HTML to a Rich Text Run.... there's some logic inside the HTML Reader that you might be able to use as the basis for this.

EDIT

Since this answer was written, a helper class has been added to the PHPExcel library that will take a basic block of simple html markup and convert it to a rich text object that can be set as a cell value. This is the PHPExcel_Helper_HTML class, with it's toRichTextObject() method, that takes an argument of a block of html and returns a Rich Text Object. There are examples demonstrating its use in Examples/42richText.php

$html = '<font color="#0000ff">
<h1 align="center">My very first example of rich text<br />generated from html markup</h1>
<p>
<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="9" color="red">
I want to eat <ins><del>healthy food</del> <strong>pizza</strong></ins>.
</font>
';

$wizard = new PHPExcel_Helper_HTML;
$richText = $wizard->toRichTextObject($html);

While not all markup is supported, and it doesn't use stylesheets, and only a limited set of inline style elements, it works well enough with basic markup elements.

Upvotes: 7

Kumar Rakesh
Kumar Rakesh

Reputation: 2708

I have spent a lot of time on this thing. But i am not getting goal. Thier is a no way write like this and get data as our wish. I apperitiate with Mark answer, Try with your own script.

Upvotes: -1

Related Questions