生活随笔
收集整理的這篇文章主要介紹了
php读取 Excel文件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
PHP版本 7.4
框架 thinkphp5.1.4
composer引入 :composer require phpoffice/phpspreadsheet
public function upload(){// 獲取表單上傳文件 例如上傳了001.jpg$file = request()->file('image');// 移動到框架應用根目錄/uploads/ 目錄下$info = $file->move('./uploads/','');$ext = $info->getExtension();$fileName = $info->getFilename();$path = './uploads/'.$fileName;$data = [];$dataSheet=[];if ($ext=='xlsx') {$reader = IOFactory::createReader('Xlsx');$reader->setReadDataOnly(true);$spreadSheet=$reader->load($path);$workSheetarr =$spreadSheet->getAllSheets();for ($i = 0; $i < count($workSheetarr); $i++){foreach($workSheetarr[$i]->getRowIterator() as $key=>$row){$cellIterator=$row->getCellIterator();$cellIterator->setIterateOnlyExistingCells(false);foreach($cellIterator as $k=>$cell){$dataSheet[$key][$k]=$cell->getValue();}}array_push($data,$dataSheet);$dataSheet = [];}}var_dump($data);}
總結
以上是生活随笔為你收集整理的php读取 Excel文件的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。