日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

原声php 读取excel乱码_使用PHPExcel读取Excel文件时会读出乱码

發(fā)布時間:2025/3/15 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 原声php 读取excel乱码_使用PHPExcel读取Excel文件时会读出乱码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這是我讀取文件的代碼:

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 < $sheetCount; $SheetID++) {$name = $sheetNames[$SheetID];$currentSheet = $PHPExcel->getSheetByName($name);$allColumn = $currentSheet->getHighestColumn();$allRow = $currentSheet->getHighestRow();$drive = new DriveCommand();$data = array();for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();//$objExcel[$name][$currentRow - 1][ord($currentColumn) - 65] = $val;$data[$currentRow][] = $val;}}if ($name == "產(chǎn)品信息") $name = "product";else if ($name == "行業(yè)") $name = "industry";else if ($name == "集團(tuán)信息"){continue; $name = "bloc";var_dump($data);die;}else if ($name == "客戶信息"){var_dump($data);die;$name = "customer";}else if ($name == "業(yè)務(wù)員信息") $name = "employeer";else continue;$drive->actionUpload($name, $data);}

這是截圖:

讀取的內(nèi)容前一部分沒有問題,后面的也沒有問題,但是中間這部分會變成這個樣子。

回復(fù)討論(解決方案)

沒有看到亂碼

截圖中的是你 var_dump 的結(jié)果

Excel文件中的數(shù)據(jù)都是正常的,但是在讀取的時候中間會有一部分讀取出類似于“ (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 } ”這樣的數(shù)據(jù)。正常的數(shù)據(jù)輸出應(yīng)該是 [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) "廣州越秀區(qū)中山三路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 的結(jié)果

Excel文件中的數(shù)據(jù)都是正常的,但是在讀取的時候中間會有一部分讀取出類似于“(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 } ”這樣的數(shù)據(jù)。正常的數(shù)據(jù)輸出應(yīng)該是[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) "廣州越秀區(qū)中山三路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問題。

是的,讀取的前一部分內(nèi)容還是正常的,后面也是正常的,但是中間就會有一部分讀出像圖片里那樣。

問題已經(jīng)解決了。是因為讀取單個cell的內(nèi)容,讀取的結(jié)果可能是object類型,也可能是string類型,加上一個判斷,修改下類型就好了。

本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請注明出處,感謝您的尊重!

總結(jié)

以上是生活随笔為你收集整理的原声php 读取excel乱码_使用PHPExcel读取Excel文件时会读出乱码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。