后端开发|php教程
excel,读出,乱码,时会,读取
后端开发-php教程
这是我读取文件的代码:
比特币交易php源码,ubuntu蓝牙搜索灰色,广州爬虫实体课,php做网页学php就够了吗,苹果seo新闻lzw
require_once dirname(__FILE__) . "/PHPExcel/Classes/PHPExcel.php";$PHPReader = new PHPExcel_Reader_Excel();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 <= $allRow; $currentRow++) {for ($currentColumn = A; $currentColumn getCellByColumnAndRow(ord($currentColumn) - 65, $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);}
这是截图:
投资理财 源码,vscode连不上商店,u盘默认在ubuntu哪个目录,tomcat增加端口,sqlite带参数写法,图片剪切上传插件,前端统一开发框架,豆瓣爬虫只有部分评论,php date 时间,佛山seo报价,html教程网站,网页解锁代码,中国美食网页设计模板下载lzw
读取的内容前一部分没有问题,后面的也没有问题,但是中间这部分会变成这个样子。
erp管理系统源码 app,ubuntu官方镜像源,tomcat安装用不了了,爬虫怎么学习教程,php验证码出不来,seo技术手册lzw
回复讨论(解决方案)
没有看到乱码
截图中的是你 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类型,加上一个判断,修改下类型就好了。