Can we include html tags inside an excel sheet using PHPExcel

Topics: Developer Forum, Project Management Forum, User Forum
Oct 13, 2010 at 2:16 PM


Can anybody tell me whether it is possible to include the html tags inside the xlsx cell, I just wanted to import some contents from a formatted html files and then create an xlsx for the same with out loosing the formatting, I use <strong>, <br>, <p>, etc..., for the formatting purpose.


Praveen Kumar. E.K.

Oct 13, 2010 at 2:37 PM

The simple answer is No! PHPExcel (and Excel) will simply treat HTML markup like <strong> within a cell as plain text.

What you can do is store "rich text" runs in a cell.

$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
$objRichText->createText(', unless specified otherwise on the invoice.');


Which will generate the formatted text:
This invoice is payable within thirty days after the end of the month unless specified otherwise on the invoice.
and store it in cell A18

There is, however, no built-in method for converting HTML to a "Rich Text" run: you'd have to write that yourself. It's something that I've been meaning to add for a while (together with an RTF to Rich Text Run conversion method), but it's pretty low down on the priority list.

Oct 15, 2010 at 9:52 AM

Thanks Mark ,

I am in process of developing a small parser that would be able to convert the Html tags to Our Rich Text Format, Once done will share the same with you.


Prraveen Kumar. V. E


Oct 15, 2010 at 10:20 AM

Thank you Praveen. That contribution would certainly be appreciated.