PHP菜鸟博客_共同学习分享PHP技术心得【PHP爱好者】
phpexcel导入,出现PHPExcel_RichText Object解决办法
2018-1-6 菜鸟站长


1.在导入excel的时候由于excel某列格式问题偶尔会出现异常情况,有的时候出现PHPExcel_RichText Object:



PHPExcel_RichText Object


                (

                    [_richTextElements:PHPExcel_RichText:private] => Array

                        (

                            [0] => PHPExcel_RichText_TextElement Object

                                (

                                    [_text:PHPExcel_RichText_TextElement:private] => 5

                                )



                            [1] => PHPExcel_RichText_Run Object

                                (

                                    [_font:PHPExcel_RichText_Run:private] => PHPExcel_Style_Font Object

                                        (

                                            [_name:protected] => Calibri

                                            [_size:protected] => 11

                                            [_bold:protected] =>

                                            [_italic:protected] =>

                                            [_superScript:protected] =>

                                            [_subScript:protected] =>

                                            [_underline:protected] => none

                                            [_strikethrough:protected] =>

                                            [_color:protected] => PHPExcel_Style_Color Object

                                                (

                                                    [_argb:protected] => FF000000

                                                    [_parentPropertyName:protected] =>

                                                    [_isSupervisor:protected] =>

                                                    [_parent:protected] =>

                                                )



                                            [_isSupervisor:protected] =>

                                            [_parent:protected] =>

                                            [colorIndex] => 8

                                        )



                                    [_text:PHPExcel_RichText_TextElement:private] => 616961627

                                )



                        )




                )



2.解决方案



import("Org.Util.PHPExcel");   // 这里不能漏掉


import("Org.Util.PHPExcel.IOFactory");

$objReader = \PHPExcel_IOFactory::createReader('Excel5');

$objPHPExcel = $objReader->load($file_name,$encode='utf-8');



/******   上面的代码可以不用看,下面的才是处理的重点     ******/

// 获取excel C2的文本

$cell = $objPHPExcel->getActiveSheet()->getCell('C2')->getValue();

// 开始格式化


if(is_object($cell)) {



    $cell= $cell->__toString();



}

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容