问题状况:在导入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. iOS系列 基础篇 06 标签和按钮 (Label & Button)

    iOS系列 基础篇 06 标签和按钮 (Label & Button) 目录: 标签控件 按钮控件 小结 标签和按钮是两个常用的控件,下面咱们逐一学习. 1. 标签控件 使用Single Vi ...

  2. PHP对象Object的概念

    类提供了一个基础,可以在此基础上创建实体(即这个类所建模的实体)的特定实例,这些特定实例称为对象(object) 例如,员工管理应用程序可能包括一个EmPloyee 类.然后可以用这个类来创建和维护特 ...

  3. zabbix完整安装

    一.nginx安装 1.必要软件准备: 为了支持rewrite功能,我们需要安装pcre: yum install pcre-* 需要ssl的支持,如果不需要ssl支持,请跳过这一步: yum ins ...

  4. swfupload 相关配置

    部署在IIS上出现404: 修改 C:\Windows\System32\inetsrv\config\applicationHost.config 文件 连续查找requestFiltering,往 ...

  5. how2heap分析系列:2_fastbin_dup

    源码 #include <stdio.h> #include <stdlib.h> int main() { printf("This file demonstrat ...

  6. 特殊文件: /dev/null和/dev/tty

    转自:http://www.cnblogs.com/stephen-liu74/archive/2011/11/10/2240461.html Linux系统提供了两个对Shell编程非常有用的特殊文 ...

  7. web前端(实习生)之 “百度一面”

    2016.3.18,星期五.我经历了我的第一次面试. 不得不说,百度是一个高效的公司,在短短一下午之间我就直接经历了一面二面,说没有压力是假的,还记得在中途等待二面的时候我至少有一小段的时间脑子是卡带 ...

  8. [LeetCode] Tenth Line 第十行

    How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...

  9. Tomcat虚拟目录配置方法及原理

    tomcat 安装好之后,只需要把你的程序包放到$Tomcat_Home$/webapps下就可以直接使用了.这样会使webapps越来越大就需要设置虚拟目录: 1.单个应用设置: 在<Host ...

  10. 关于CAJViewer 无法获取document路径问题

    修改注册表 进入注册表编辑器: win+R >>输入 regedit  如下图: 修改关键注册表项(两项相同值应同时修改) 1.HKEY_CURRENT_USER\Software\Mic ...