Home > Article > Backend Development > PHP implementation to obtain excel file data
This article mainly introduces the method of obtaining excel file data in php. Has very good reference value. Let’s take a look at it with the editor.
It’s very simple to implement. Here’s a brief introduction for you
1. Download the PHPExcel class, which is a folder and must have One file PHPExcel.php, two in the same directory
require __DIR__ . './PHPExcel/IOFactory.php'; $PHPReader = new \PHPExcel_Reader_Excel2007(); //判断文件类型 if (!$PHPReader->canRead($filePath)) { $PHPReader = new \PHPExcel_Reader_Excel5(); if (!$PHPReader->canRead($filePath)) { echo 'no Excel'; return false; } } $PHPExcel = $PHPReader->load($filePath); /**读取excel文件中的第一个工作表*/ $currentSheet = $PHPExcel->getSheet(0); /**取得最大的列号*/ $allColumn = $currentSheet->getHighestColumn(); /**取得一共有多少行*/ $allRow = $currentSheet->getHighestRow(); /**从第1行开始输出*/ for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) { /**从第A列开始输出*/ for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) { $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue(); /**ord()将字符转为十进制数*/ $date[$currentRow - 1][] = $val; } } return $date;
The above is the entire content of this article, I hope it will be helpful to everyone learning helps.
Related recommendations:
PHP Implemented browser inspection class_php skills
PHP Implemented browser inspection class _php skills
PHP Implemented through parameters Generate a complete instance of MYSQL statement class_php tips
The above is the detailed content of PHP implementation to obtain excel file data. For more information, please follow other related articles on the PHP Chinese website!