问题状况:在导入excel的时候会出现

PHPExcel_RichText Object ( [_richTextElements:PHPExcel_RichText:private] => Array ( [] => PHPExcel_RichText_Run Object ( [_font:PHPExcel_RichText_Run:private] => PHPExcel_Style_Font Object ( [_name:protected] => 細明體 [_size:protected] =>  [_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] =>  ) [_text:PHPExcel_RichText_TextElement:private] => 蜜糖皇后暖色胭脂 ) [] => PHPExcel_RichText_Run Object ( [_font:PHPExcel_RichText_Run:private] => PHPExcel_Style_Font Object ( [_name:protected] => Calibri [_size:protected] =>  [_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] =>  ) [_text:PHPExcel_RichText_TextElement:private] => The Honey Queen Honeycomb Blusher ) ) )

解决办法

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

事例参考 $file_name=“xxx.xls”

public function excel($file_name){
//$file_name= './Upload/excel/123456.xls';
import("Org.Util.PHPExcel"); // 这里不能漏掉
import("Org.Util.PHPExcel.IOFactory");
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load($file_name,$encode='utf-8');
$sheet = $objPHPExcel->getSheet();
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数 for($i=;$i<$highestRow+;$i++){
$data[$i]['a'] = $objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue();
$data[$i]['b'] = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->getValue();
$data[$i]['c'] = $objPHPExcel->getActiveSheet()->getCell('C'.$i)->getValue();
$data[$i]['d'] = $objPHPExcel->getActiveSheet()->getCell('D'.$i)->getValue();
$data[$i]['e'] = $objPHPExcel->getActiveSheet()->getCell('E'.$i)->getValue();
$data[$i]['f'] = $objPHPExcel->getActiveSheet()->getCell('F'.$i)->getValue();
$data[$i]['g'] = $objPHPExcel->getActiveSheet()->getCell('G'.$i)->getValue(); //格式化数据
if(is_object($data[$i]['a'])) $data[$i]['a']= $data[$i]['a']->__toString();
if(is_object($data[$i]['b'])) $data[$i]['b']= $data[$i]['b']->__toString();
if(is_object($data[$i]['c'])) $data[$i]['c']= $data[$i]['c']->__toString();
if(is_object($data[$i]['d'])) $data[$i]['d']= $data[$i]['d']->__toString();
if(is_object($data[$i]['e'])) $data[$i]['e']= $data[$i]['e']->__toString();
if(is_object($data[$i]['f'])) $data[$i]['f']= $data[$i]['f']->__toString();
if(is_object($data[$i]['g'])) $data[$i]['g']= $data[$i]['g']->__toString();
} return $data; }

phpexcel 字符串转码的更多相关文章

  1. 大数据学习--day13(字符串String--源码分析--JVM内存分析)

    字符串String--源码分析--JVM内存分析 String 类的对象 , 是不可变的字符串对象呢 这个不可变很重要,之后要讲的intern()也离不开它的不可变性. https://www.cnb ...

  2. Java 字符串转码工具类

    StringConvertUtils.java package javax.utils; /** * 字符串转码工具类 * * @author Logan * @createDate 2019-04- ...

  3. java 字符串 转码

    //xmlStr 为需要转码的字符串 UTF-8 可改为不同的编码格式 如:GBK //亲测可用 仅供参考 String xmlStrs=""; try{ xmlStrs=new ...

  4. Java_Web___字符串转码String.getBytes()和new String()——(转)

    转载自:http://zhuhuide2004.iteye.com/blog/562739:转载请注明原作者地址: 在Java中,String.getBytes(String decode)方法会根据 ...

  5. 后台构建 html 字符串传到前台字符串转码(html)处理

    知识在于总结,那就记下了吧! 例如后台 html 字符串是 var htmlStr="后台html字符串": 转码 var html格式代码=decodeHtml(htmlStr) ...

  6. [C/C++]_[VS2010来源与UTF8中国字符串转码ANSI问题]

    现场: 1.思想vs设置源文件UTF8编码,代码中国串出现在它必须是utf8编码,不幸的是,,假定源代码将出现在中国字符串,在存储器中转码ANSI编码. Unicode(UTF8签名) 代码页(650 ...

  7. 字符串ASCII码排序

    在对接第三方支付渠道的时候,第三方会要求参数按照ASCII码从小到大排序. 如下是渠道方有关生成签名规则的java代码示例: //初始化0010merkey.private文件: String mer ...

  8. 字符串转码【String.getBytes()和new String()】

    在Java中,String.getBytes(String decode)方法会根据指定的decode编码返回某字符串在该编码下的byte数组表示,如 byte[] b_gbk = "中&q ...

  9. Redis 数据结构-字符串源码分析

    相关文章 Redis 初探-安装与使用 Redis常用指令 本文将从以下几个部分进行介绍 1.前言 2.常用命令 3.字符串结构 4.字符串实现 5.命令是如果操作字符串的 前言 平时在使用 Redi ...

随机推荐

  1. 模块化之Spring3.0 web fragment和gradle构建项目

      1.背景 模块化开发很久以前就开始普及的概念.但是到了企业实际情况中,真正把模块化作为系统架构的核心的不多.或者说对模块化有这个意识,但是具体到底该如何实现,有些模糊,同时也许因为项目紧.任务中. ...

  2. 5种处理js跨域问题方法汇总(转载)

    1.JSONP跨域GET请求 ajax请求,dataType为jsonp.这种形式需要请求在服务端调整为返回callback([json-object])的形式.如果服务端返回的是普通json对象.那 ...

  3. JavaScript(八)——复习一(重要内容基本包含在内)

    一.常用对话框 1.alert(""):警告对话框,作用是弹出一个警告对话框 2.confirm(""):确定对话框,弹出一个带确定和取消按钮的对话框——确定返 ...

  4. linux基本知识

    1.默认不写端口号就是80端口   127.0.0.1.localhost都代表本机 2.linux下的用户管理: id:可以查看当前用户whoami:查看当前的用户who:看当前已经登录的用户w:也 ...

  5. Linq语法学习

    关键词: select from where in into join on equals orderby descending DefaultIfEmpty() thenby submitChang ...

  6. 在output 子句和 scope_identity() 混合使用的时候的注意事项

    无意睹到一篇旧文档 SR0008:考虑使用 SCOPE_IDENTITY 代替 @@IDENTITY :https://msdn.microsoft.com/zh-cn/library/dd17212 ...

  7. Mac下QT错误,Xcode配置解决办法

    出现错误: Xcode not set up properly. You may need to confirm the license agreement by running / 解决办法如下: ...

  8. x01.BSheepTree: 树

    数据结构,无外乎三: 1. 一对一,线性表,数组是也: 2. 一对多,树,菜单是也: 3. 多对多,图,网络是也. 涉及到树,有一个平衡的问题,左旋转,右旋转,转得人晕晕乎乎.好在陈广的<数据结 ...

  9. Linux工具快速教程

    看到一linux中常用工具使用教程,非常好.猛击下面的地址 github:https://github.com/me115/linuxtools_rst 在线文档:http://linuxtools- ...

  10. pitch yaw roll是什么

    虚拟现实 三维空间的右手笛卡尔坐标如图1所示. 图1 在航空中,pitch, yaw, roll如图2所示. pitch是围绕X轴旋转,也叫做俯仰角,如图3所示. yaw是围绕Y轴旋转,也叫偏航角,如 ...