PHPExcel simple example of reading excel file, _PHP tutorial

WBOY
Release: 2016-07-12 08:50:49
Original
826 people have browsed it

An example of how PHPExcel can simply read an excel file.

The example in this article describes how PHPExcel can simply read an excel file. Share it with everyone for your reference, the details are as follows:

PHP Excel 2007 classes
Project providing a set of classes for the PHP programming language, which allow you to write to and read from different file formats, like Excel 2007, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.

Download address:
http://phpexcel.codeplex.com/

Read 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] != 'T'; $column++) {
    $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
    echo $val;
  }
}

Copy after login

Supplement: The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:

php code online formatting and beautification tool:

http://tools.jb51.net/code/phpformat

In addition, since php belongs to the C language style, the following tool can also format php code:

C language style/HTML/CSS/json code formatting and beautification tool:
http://tools.jb51.net/code/ccode_html_css_json

Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Complete of PHP array (Array) operation skills", " PHP Sorting Algorithm Summary", "PHP Common Traversal Algorithms and Techniques Summary", PHP Data Structure and Algorithm Tutorials, PHP Programming Algorithm Summary, PHP Mathematical Operation Techniques Summary, PHP Regular Expression Usage Summary, "Summary of PHP operations and operator usage", "Summary of PHP string usage" and "Summary of common PHP database operation skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133074.htmlTechArticleAn example of how PHPExcel can simply read an excel file. This example describes how PHPExcel can simply read an excel file. Share it with everyone for your reference, the details are as follows: PHP Excel 2007 classes Pro...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template