Home  >  Article  >  Backend Development  >  How to read excel files in phpexcel

How to read excel files in phpexcel

WBOY
WBOYOriginal
2016-07-25 08:53:03988browse
  1. $reader = PHPExcel_IOFactory::createReader('Excel5'); // How to read excel files. This method is to read the version before excel2007. To read the version after 2007, you can also check the ClassesPHPExcelReader folder. Class (for all reading classes, just fill in the one you need)
  2. $PHPExcel = $reader->load("info.xls"); // File name
  3. $sheet = $PHPExcel->getSheet(0) ; // Read the first worksheet starting from 0
  4. $highestRow = $sheet->getHighestRow(); // Get the total number of rows
  5. $highestColumn = $sheet->getHighestColumn(); // Get the total columns Number
  6. // Modify according to the size of your own data table
  7. $arr = array(1=>'A',2=>'B',3=>'C',4=>'D', 5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11= >'K',12=>'L',13=>'M', 14=>'N',15=>'O',16=>'P',17=> 'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W ',24=>'X',25=>'Y',26=>'Z');
  8. // Read one row at a time, and then loop the values ​​of each column in the row
  9. for ($ row = 5; $row <= $highestRow; $row++) {
  10. for ($column = 1; $arr[$column] != 'T'; $column++) {
  11. $val = $sheet->getCellByColumnAndRow ($column, $row)->getValue();
  12. $list[$row][] = $val;
  13. }
  14. }
  15. print_r($list);
Copy code


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