Home > Article > Backend Development > How to read data in excel in php
1. Set up a PHP program running environment to execute the program, as long as the program can run
2. Download PHPExcel. php class files and related components
3. Include it in the file to be run require PHPExcel.php, create the object by default Use excel2007 to read excel. If the format is incorrect, use the previous version to read
4. Read excel There can be multiple worksheets. If you only need to read the first one, use $PHPExcel->getSheet(0). If there are multiple worksheets, operate the other contents in a loop
5. Get the rows and columns of the excel table respectively
$allColumn = $currentSheet->getHighestColumn(); /**取得一共有多少行*/ $allRow = $currentSheet->getHighestRow(); /**从第二行开始输出,因为excel表中第一行为列名*/
6. Read the corresponding data in a double loop of rows and columns
for($currentRow = 2;$currentRow <= 98;$currentRow++){ /**从第A列开始输出*/ echo"<tr>"; //for($currentColumn= 'A';$currentColumn<= $allColumn; $currentColumn++){ $cancername=""; for($currentColumn= 'A';$currentColumn<='B'; $currentColumn++){
Two for cross-positioning can read the cell data
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to read data in excel in php. For more information, please follow other related articles on the PHP Chinese website!