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.    

转载于:https://www.cnblogs.com/liangzia/p/10516569.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值