phpexcel导入,出现PHPExcel_RichText Object解决办法

  • 内容
  • 评论
  • 相关

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();

}

本文标签:

版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。

本文链接:phpexcel导入,出现PHPExcel_RichText Object解决办法 - https://www.wlphp.com/?post=145

phpexcel导入,出现PHPExcel_RichText Object解决办法

发表评论

电子邮件地址不会被公开。 必填项已用*标注