Aug 29, 2008 at 4:21 AM
Edited Aug 29, 2008 at 4:21 AM
PHPExcel_RichText read richtext cell value
Aug 29, 2008 at 11:33 AM
How about this?

$plainText = ($cell->getValue() instanceof PHPExcel_RichText) ?
    $cell->getValue()->getPlainText() : $cell->getValue();
echo $plainText;   
Sep 4, 2008 at 9:28 AM
Edited Sep 4, 2008 at 9:37 AM
that doesnt work on my part, all i am getting is a 0. is there a different way to read the text from a RichText field?

i also tried following:

$form_name = $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getValue();

if (is_object($form_name)) {
    $objRichText = new PHPExcel_RichText($objPHPExcel->getActiveSheet()->getCell('B' . $i));
    $form_name = $objRichText->getPlainText();

echo $form_name . "<br>";

Object of class PHPExcel_RichText could not be converted to string in /formlist/classes/PHPExcel/RichText.php on line 149

is this a PHPExcel bug?

Because the excel sheet i am reading has normal cells and RichText cells and i need the text of both, just the text without the format

Sep 4, 2008 at 10:10 AM
If you need just the plain text then probably the right solution for you is to use setReadDataOnly(true) for the reader.


$reader = new PHPExcel_Reader_Excel2007();

$PHPExcel = $reader->load('test.xlsx');

$ws = $PHPExcel->getActiveSheet();

// A1 contains Rich-Text
echo $ws->getCell('A1')->getValue();

It is important that you use the latest source found under 'Source Code' as the behavior was changed after the release of PHPExcel 1.6.3. Until recently you would get Rich-Text even with setReadDataOnly(true).

Sep 4, 2008 at 3:02 PM
hallo koyama, the thing is, that i need to use the excel7 reader and as far as i know (because i tried it)
$reader->setReadDataOnly(true); doesnt work there.

anyway, i still got to finish my job, maybe someone needs that info in the future, here is my source code:

        $form_name = $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getValue();
        if (is_object($form_name)) { // if the field happens to contain richtext

            $objRichText = new PHPExcel_RichText($objPHPExcel->getActiveSheet()->getCell('B' . $i));
            $elements = $objRichText->getRichTextElements();
            $objRichText2 = $elements[0]->getText(); // judging from the $objRichtText->PlainText method, this should have the plaintext, but instead it is another object, so we need to get the rich text elements again

            $elements2 = $objRichText2->getRichTextElements();
            $returnValue = "";
            foreach ($elements2 as $text) {
                $returnValue .= $text->getText();

            $form_name = $returnValue; // this has the plaintext now

Sep 4, 2008 at 3:12 PM
You mean Excel5 reader? In that case setReadDataOnly(true) should be working too and it will give you plain text without any extra effort.

I see what you are doing in your code, but this shouldn't be necessary when you use setReadDataOnly(true). Again, you need to use latest source as this behavior was added after version 1.6.3. PHPExcel 1.6.3 will not be working.
Sep 4, 2008 at 4:01 PM
yes i mean the excel5 reader, and yes i only have the 1.6.3 installed. i might try a snapshot later
Apr 15, 2009 at 10:01 AM
Does Excel5 writer support RichText?
as I can see from generated Excel5 file, it doesn't support it. Am I right?
If it doesn't, are you going to implement it in the future?
Apr 16, 2009 at 5:28 AM
@AzriMan: Yes, Rich-Text is on the wish list for Excel5 writer:

Some restructuring of the code from PEAR Spreadsheet_Excel_Writer is necessary.

Apr 28, 2012 at 3:48 PM

Hi everyone, I have a some little problem with phpexcel. In the excel file(csv) the description cell contains on html elements i.e{<table>, <p>, <b> font so on....}. Each excel cell is heavy therefore i need proper method which will deal with html. Is there any function or method in phpexcel that will handle this html cell data and take it from excel and insert into database from start to end? If yes please give me at least one example. Thanks