phpexcel 字符串转码
问题状况:在导入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 字符串转码的更多相关文章
- 大数据学习--day13(字符串String--源码分析--JVM内存分析)
字符串String--源码分析--JVM内存分析 String 类的对象 , 是不可变的字符串对象呢 这个不可变很重要,之后要讲的intern()也离不开它的不可变性. https://www.cnb ...
- Java 字符串转码工具类
StringConvertUtils.java package javax.utils; /** * 字符串转码工具类 * * @author Logan * @createDate 2019-04- ...
- java 字符串 转码
//xmlStr 为需要转码的字符串 UTF-8 可改为不同的编码格式 如:GBK //亲测可用 仅供参考 String xmlStrs=""; try{ xmlStrs=new ...
- Java_Web___字符串转码String.getBytes()和new String()——(转)
转载自:http://zhuhuide2004.iteye.com/blog/562739:转载请注明原作者地址: 在Java中,String.getBytes(String decode)方法会根据 ...
- 后台构建 html 字符串传到前台字符串转码(html)处理
知识在于总结,那就记下了吧! 例如后台 html 字符串是 var htmlStr="后台html字符串": 转码 var html格式代码=decodeHtml(htmlStr) ...
- [C/C++]_[VS2010来源与UTF8中国字符串转码ANSI问题]
现场: 1.思想vs设置源文件UTF8编码,代码中国串出现在它必须是utf8编码,不幸的是,,假定源代码将出现在中国字符串,在存储器中转码ANSI编码. Unicode(UTF8签名) 代码页(650 ...
- 字符串ASCII码排序
在对接第三方支付渠道的时候,第三方会要求参数按照ASCII码从小到大排序. 如下是渠道方有关生成签名规则的java代码示例: //初始化0010merkey.private文件: String mer ...
- 字符串转码【String.getBytes()和new String()】
在Java中,String.getBytes(String decode)方法会根据指定的decode编码返回某字符串在该编码下的byte数组表示,如 byte[] b_gbk = "中&q ...
- Redis 数据结构-字符串源码分析
相关文章 Redis 初探-安装与使用 Redis常用指令 本文将从以下几个部分进行介绍 1.前言 2.常用命令 3.字符串结构 4.字符串实现 5.命令是如果操作字符串的 前言 平时在使用 Redi ...
随机推荐
- CentOS如何查看硬盘品牌型号等具体信息
首先使用smartctl --all /dev/sda 指令来检查硬盘信息,该指令CentOS自带,得到的结果可能如下: smartctl 5.43 2012-06-30 r3573 [x86_64- ...
- NFS服务器搭建——可用于共享文件或负载均衡文件共享服务器使用
一.软件包安装 yum -y install nfs-utils rpcbind 二.服务器端配置共享目录 1. 在服务器上创建NFS共享目录:mkdir /usr/local/test 2. 设置 ...
- DOS下windows系统查看wifi密码
DOS下windows系统查看wifi密码 首先,按win+R键,win键如下 弹出框中输入cmd 在弹出界面输入 netsh wlan show profiles 你可以看到你链接过的所有wifi名 ...
- 3-EM的安装和使用
EM的安装和使用 一.EM工具的安装和使用 1.保证数据库启动 2.保证侦听启用 3.通过这个命令可以查看到侦听端口1521的状态信息 4.启动em工具 5.查看em工具是否运行 6.登陆网站并进行操 ...
- VS2013无法启动 IIS Express Web解决办法
开发环境:windows8.1+VS2013 使用VS2013有一段时间了,因前期都是编写C/S程序,没有使用到B/S调试器.前几日,创建了一个MVC项目,突然发现VS2013无法调试,报了这样的错. ...
- [转]OAuth 2.0 - Authorization Code授权方式详解
本文转自:http://www.cnblogs.com/highend/archive/2012/07/06/oautn2_authorization_code.html I:OAuth 2.0 开发 ...
- 使用DFA做文本编辑器的自动提示
之前看龙书的时候,龙书提到可以在编译器里用动态的生成的NFA自动机来动态匹配自己的输入串,NFA的简单实现其实写起来非常简单,但是我是实际凭感觉写完之后,却觉得并不是非常的好用,在处理自己已经输入过的 ...
- python爬虫学习(8) —— 关于4399的一个小Demo
堂弟喜欢各种游戏,在没有网络的情况下,上4399显得很无力. 另外,4399广告好多,,而且加载慢.. 怎么办,,写个爬虫吧,,把4399上的"好玩"游戏爬下来. 1. 分析阶段 ...
- [No000090]C#捕获控制台(console)关闭事件及响应cmd快捷键
捕获控制台(console)关闭事件: 1.Ctrl+C信号: 2.Ctrl+Break信号: 3.用户系统关闭Console时: 4.用户退出系统时: 5.系统将要关闭时: using System ...
- python 小程序 复制目录树
1. 将一个目录树完全复制到另外一个目录下面 import os, sys """ 复制目录树 """ maxloadsize = 1024 ...