zoukankan      html  css  js  c++  java
  • PHPEXCEL读出数据是PHPExcel_RichText类型

    今天在做导入EXCEL数据时,而且单元格里的数据类型改成文本类型后,在PHPEXCEL读出来的是PHPExcel_RichText类型的,这类型使getValue()是不管用了,因为这时候getValue()返回的PHPExcel_RichText(下面是PHPExcel_RichText数据保存格式)是一个Object类型了,所以在插入数据的时候就为空。

    1.  PHPExcel_RichText Object 
    2.     [_richTextElements:PHPExcel_RichText:private] => Array 
    3.         ( 
    4.             [0] => PHPExcel_RichText_TextElement Object 
    5.                 ( 
    6.                     [_text:PHPExcel_RichText_TextElement:private] => l 
    7.                 ) 
    8.  
    9.             [1] => PHPExcel_RichText_Run Object 
    10.                 ( 
    11.                     [_font:PHPExcel_RichText_Run:private] => PHPExcel_Style_Font Object 
    12.                         ( 
    13.                             [_name:protected] => Calibri 
    14.                             [_size:protected] => 11 
    15.                             [_bold:protected] =>  
    16.                             [_italic:protected] =>  
    17.                             [_superScript:protected] =>  
    18.                             [_subScript:protected] =>  
    19.                             [_underline:protected] => none 
    20.                             [_strikethrough:protected] =>  
    21.                             [_color:protected] => PHPExcel_Style_Color Object 
    22.                                 ( 
    23.                                     [_argb:protected] => FF000000 
    24.                                     [_parentPropertyName:protected] =>  
    25.                                     [_isSupervisor:protected] =>  
    26.                                     [_parent:protected] =>  
    27.                                 ) 
    28.  
    29.                             [_isSupervisor:protected] =>  
    30.                             [_parent:protected] =>  
    31.                             [colorIndex] => 8 
    32.                         ) 
    33.  
    34.                     [_text:PHPExcel_RichText_TextElement:private] => isimin 
    35.                 ) 
    36.  
    37.         ) 
    38.  


    解决方法如下:
     

      1. $cell = $currentSheet->getCell($addr)->getValue();//获取对应值  
      2.   if($cell instanceof PHPExcel_RichText){ 
      3.         //富文本转换字符串 这里非常的重要
      4.           $cell = $cell->__toString();  
      5. }
      6.    
  • 相关阅读:
    还有为window.close()方法弹出的询问窗口烦?
    ValidateTextBox发布绝对实用
    面向对象设计的11个原则
    关于建立控件、组件开发团队,有兴趣的网友请留言
    存储过程和触发器要使用链接服务器时要注意的一点
    “这块布的艺术成分都几高唧!”“有几高啊?”“三、四层楼那么高啦。”
    有没有人用过负离子发生器?
    摇滚你的页面。Free:RockUControl控件发布,开源:RevealTransitionImage
    控件开发团队序言及加入说明
    一些平时能用到的CSS效果(ZT+YC)
  • 原文地址:https://www.cnblogs.com/liangzia/p/10516569.html
Copyright © 2011-2022 走看看