Home  >  Article  >  Backend Development  >  PHPExcel implements methods and simple examples of reading excel files

PHPExcel implements methods and simple examples of reading excel files

墨辰丷
墨辰丷Original
2018-06-02 09:58:342382browse

This article mainly introduces the method of PHPExcel to simply read excel files, and briefly analyzes PHPExcel's reading operation skills for Excel files in the form of examples. Friends in need can refer to the following

Reading an excel file, and get an example of the content of each row and column:

set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');
include 'PHPExcel/IOFactory.php';
$reader = PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
$PHPExcel = $reader->load($excelfilename); // 文档名称
$sheet = $PHPExcel->getSheet(0); // 读取第一个工作表(编号从 0 开始)
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
$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');
//echo $highestRow.$highestColumn;
// 一次读取一列
for ($row = 5; $row <= $highestRow; $row++) {
  for ($column = 0; $arr[$column] != &#39;T&#39;; $column++) {
    $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
    echo $val;
  }
}

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

phpSharing of methods for developing custom menus on WeChat

PHP MySQL implements fuzzy query Employee information function

phpDetailed explanation of WeChat development access example

The above is the detailed content of PHPExcel implements methods and simple examples of reading excel files. 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