Getting Text Instead of RTF/Objects from PHPExcel Reading

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Getting Text Instead of RTF/Objects from PHPExcel Reading

文章 yehlu »

http://stackoverflow.com/questions/1562 ... el-reading

代碼: 選擇全部

[2]=> object(PHPExcel_RichText_Run)#182 (2) 
            { 
                ["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#189 (12) 
                { 
                    ["_name":"PHPExcel_Style_Font":private]=> string(14) "Century Gothic" 
                    ["_size":"PHPExcel_Style_Font":private]=> string(2) "10" 
                    ["_bold":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_italic":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_superScript":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_subScript":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_underline":"PHPExcel_Style_Font":private]=> string(4) "none" 
                    ["_strikethrough":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_color":"PHPExcel_Style_Font":private]=> object(PHPExcel_Style_Color)#188 (4) 
                    { 
                        ["_argb":"PHPExcel_Style_Color":private]=> string(8) "FF000000" 
                        ["_isSupervisor":"PHPExcel_Style_Color":private]=> bool(false) 
                        ["_parent":"PHPExcel_Style_Color":private]=> NULL 
                        ["_parentPropertyName":"PHPExcel_Style_Color":private]=> NULL 
                    } 
                    ["_parentPropertyName":"PHPExcel_Style_Font":private]=> NULL 
                    ["_isSupervisor":"PHPExcel_Style_Font":private]=> bool(false) 
                    ["_parent":"PHPExcel_Style_Font":private]=> NULL 
                } 
                ["_text":"PHPExcel_RichText_TextElement":private]=> string(14) "& TECHNOLOGIES" 
            } 
That crazy insane looking PHPExcel Object is a Rich Text object, a cell value that contains formatted text.

You can test if a cell contains a Rich Text object using:

代碼: 選擇全部

if ($objPHPExcel->getActiveSheet->getCell('A1')->getValue() instanceof PHPExcel_RichText)
and extract the plain text content from the cell using

代碼: 選擇全部

$plaintext = $objPHPExcel->getActiveSheet->getCell('A1')->getValue()->getPlainText();
回覆文章

回到「PHP」