Home  >  Article  >  Backend Development  >  How to read data in excel in php

How to read data in excel in php

王林
王林Original
2019-09-24 13:04:307858browse

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

How to read data in excel in php

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

How to read data in excel in php

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

How to read data in excel in php

5. Get the rows and columns of the excel table respectively

$allColumn = $currentSheet->getHighestColumn(); 
/**取得一共有多少行*/ 
$allRow = $currentSheet->getHighestRow(); 
/**从第二行开始输出,因为excel表中第一行为列名*/

How to read data in excel in php

6. Read the corresponding data in a double loop of rows and columns

for($currentRow = 2;$currentRow <= 98;$currentRow++){ 
/**从第A列开始输出*/ 
echo"<tr>";
//for($currentColumn= &#39;A&#39;;$currentColumn<= $allColumn; $currentColumn++){ 
$cancername="";
for($currentColumn= &#39;A&#39;;$currentColumn<=&#39;B&#39;; $currentColumn++){

Two for cross-positioning can read the cell data

How to read data in excel in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn