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 ...
随机推荐
- java中IO流异常处理
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...
- Oracle汉字转拼音package
--函数GetHzFullPY(string)用于获取汉字字符串的拼音 --select GetHzFullPY('中华人民共和国') from dual; --返回:ZhongHuaRenMinGo ...
- EF和MVC系列文章导航:EF Code First、DbContext、MVC
对于之前一直使用webForm服务器控件.手写ado.net操作数据库的同学,突然来了EF和MVC,好多新概念泉涌而出,的确犹如当头一棒不知所措.本系列文章可以帮助新手入门并熟练使用EF和MVC,有了 ...
- 办公OA的登陆界面..
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Hadoop技巧(02):时间同步
阅读目录 序 时间同步 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 在实际部署 ...
- 安装KVM及虚拟机
创建lvm 安装kvm相关的包 需要安装的包 安 ...
- __dbg.h
#ifndef __HSS_DBG_HSS__ #define __HSS_DBG_HSS__ /*************************************************** ...
- C#通过属性名称获取(读取)属性值的方法
之前在开发一个程序,希望能够通过属性名称读取出属性值,但是由于那时候不熟悉反射,所以并没有找到合适的方法,做了不少的重复性工作啊! 然后今天我再上网找了找,被我找到了,跟大家分享一下. 其实原理并不复 ...
- 解读ASP.NET 5 & MVC6系列(8):Session与Caching
在之前的版本中,Session存在于System.Web中,新版ASP.NET 5中由于不在依赖于System.Web.dll库了,所以相应的,Session也就成了ASP.NET 5中一个可配置的模 ...
- [LeetCode] Find the Duplicate Number 寻找重复数
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...