1.在导入excel的时候由于excel某列格式问题偶尔会出现异常情况,有的时候出现
PHPExcel_RichText Object: PHPExcel_RichText Object ( [_richTextElements:PHPExcel_RichText:private] => Array ( [0] => PHPExcel_RichText_TextElement Object ( [_text:PHPExcel_RichText_TextElement:private] => 5 ) [1] => PHPExcel_RichText_Run Object ( [_font:PHPExcel_RichText_Run:private] => PHPExcel_Style_Font Object ( [_name:protected] => Calibri [_size:protected] => 11 [_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] => 8 ) [_text:PHPExcel_RichText_TextElement:private] => 616961627 ) ) )
2.解决方案
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)) {undefined
$cell= $cell->__toString();
}