您好,欢迎访问一九零五行业门户网

使用PHPExcel读取Excel文件时会读出乱码

这是我读取文件的代码:
require_once dirname(__file__) . /phpexcel/classes/phpexcel.php; $phpreader = new phpexcel_reader_excel2007(); if (!$phpreader->canread($filepath)) { $phpreader = new phpexcel_reader_excel5(); if (!$phpreader->canread($filepath)) { echo no file; die; } } $phpexcel = $phpreader->load($filepath); $sheetcount = $phpexcel->getsheetcount(); $sheetnames = $phpexcel->getsheetnames(); for ($sheetid = 0; $sheetid getsheetbyname($name); $allcolumn = $currentsheet->gethighestcolumn(); $allrow = $currentsheet->gethighestrow(); $drive = new drivecommand(); $data = array(); for ($currentrow = 1; $currentrow getvalue(); //$objexcel[$name][$currentrow - 1][ord($currentcolumn) - 65] = $val; $data[$currentrow][] = $val; } } if ($name == 产品信息) $name = product; else if ($name == 行业) $name = industry; else if ($name == 集团信息){ continue; $name = bloc; var_dump($data); die; } else if ($name == 客户信息) { var_dump($data); die; $name = customer; } else if ($name == 业务员信息) $name = employeer; else continue; $drive->actionupload($name, $data); }
这是截图:
读取的内容前一部分没有问题,后面的也没有问题,但是中间这部分会变成这个样子。
回复讨论(解决方案) 没有看到乱码
截图中的是你 var_dump 的结果
excel文件中的数据都是正常的,但是在读取的时候中间会有一部分读取出类似于“ (12) { [_name:protected]=> string(6) 宋体 [_size:protected]=> int(12) [_bold:protected]=> bool(false) [_italic:protected]=> bool(false) [_superscript:protected]=> bool(false) [_subscript:protected]=> bool(false) [_underline:protected]=> string(4) none [_strikethrough:protected]=> bool(false) [_color:protected]=> object(phpexcel_style_color)#3006 (4) { [_argb:protected]=> string(8) ff000000 [_parentpropertyname:protected]=> null [_issupervisor:protected]=> bool(false) [_parent:protected]=> null } ”这样的数据。正常的数据输出应该是 [2]=> array(13) { [0]=> string(6) b01001 [1]=> string(6) 超市 [2]=> string(12) 百佳超市 [3]=> string(6) 广东 [4]=> string(6) 广州 [5]=> string(21) 广州中华广场店 [6]=> string(51) 广州越秀区中山三路228号中华广场三层 [7]=> null [8]=> null [9]=> null [10]=> null [11]=> float(2735) [12]=> string(6) caoshi } [3]=> array(13) { [0]=> string(6) b01002 [1]=> string(6) 超市 [2]=> string(12) 百佳超市  这种格式。
我也有时候会碰到乱码,有时候又是好的,估计是微软excel问题。
没有看到乱码
截图中的是你 var_dump 的结果
excel文件中的数据都是正常的,但是在读取的时候中间会有一部分读取出类似于“(12) { [_name:protected]=> string(6) 宋体 [_size:protected]=> int(12) [_bold:protected]=> bool(false) [_italic:protected]=> bool(false) [_superscript:protected]=> bool(false) [_subscript:protected]=> bool(false) [_underline:protected]=> string(4) none [_strikethrough:protected]=> bool(false) [_color:protected]=> object(phpexcel_style_color)#3006 (4) { [_argb:protected]=> string(8) ff000000 [_parentpropertyname:protected]=> null [_issupervisor:protected]=> bool(false) [_parent:protected]=> null } ”这样的数据。正常的数据输出应该是[2]=> array(13) { [0]=> string(6) b01001 [1]=> string(6) 超市 [2]=> string(12) 百佳超市 [3]=> string(6) 广东 [4]=> string(6) 广州 [5]=> string(21) 广州中华广场店 [6]=> string(51) 广州越秀区中山三路228号中华广场三层 [7]=> null [8]=> null [9]=> null [10]=> null [11]=> float(2735) [12]=> string(6) caoshi } [3]=> array(13) { [0]=> string(6) b01002 [1]=> string(6) 超市 [2]=> string(12) 百佳超市  这种格式。
我也有时候会碰到乱码,有时候又是好的,估计是微软excel问题。
是的,读取的前一部分内容还是正常的,后面也是正常的,但是中间就会有一部分读出像图片里那样。 问题已经解决了。是因为读取单个cell的内容,读取的结果可能是object类型,也可能是string类型,加上一个判断,修改下类型就好了。
其它类似信息

推荐信息