Phpexcel reading an Excel file sample

Source: Internet
Author: User

Phpexcel Class Library: Https://github.com/PHPOffice/PHPExcel

Reprinted from: http://www.imhdr.com/1332/comment-page-1/

Phpexcel is a very convenient class to generate Excel format files, the official download package contains a lot of examples of how to generate various styles of Excel files, but not a complete example of reading Excel files. Xiaoqiang According to the information on the Internet, Compiled an example of simply reading an Excel file.
Traditional methods:

<?PHP/** * * * @copyright 2007-2012 xiaoqiang. * @author xiaoqiang.wu <[email protected]> * @version 1.01*/ error_reporting(E_all); Date_default_timezone_set (' Asia/shanghai '); /** Phpexcel_iofactory*/require_once‘.. /classes/phpexcel/iofactory.php '; //Check Prerequisitesif(!file_exists("31excel5.xls")) {    Exit("Not Found 31excel5.xls.\n");} $reader= Phpexcel_iofactory::createreader (' Excel5 ');//set in EXCEL5 format (excel97-2003 workbook)$PHPExcel=$reader->load ("31excel5.xls");//Loading Excel Files$sheet=$PHPExcel->getsheet (0);//read the first worksheet$highestRow=$sheet->gethighestrow ();//total number of rows obtained$highestColumm=$sheet->gethighestcolumn ();//total number of columns obtained$highestColumm= Phpexcel_cell::columnindexfromstring ($colsNum);//the alphabetical column is converted to a numeric column such as: AA to /** Iterate through each cell's data*/ for($row= 1;$row<=$highestRow;$row++){//The number of rows starts at line 1th     for($column= 0;$column<$highestColumm;$column++) {//the number of columns starts with column NO. 0        $columnName= Phpexcel_cell::stringfromcolumnindex ($column); Echo $columnName.$row.":".$sheet->getcellbycolumnandrow ($column,$row)->getvalue (). " <br/> "; }} ?>

Streamlined method:

<?PHP/** * * * @copyright 2007-2012 xiaoqiang. * @author xiaoqiang.wu <[email protected]> * @version 1.01*/ error_reporting(E_all); Date_default_timezone_set (' Asia/shanghai '); /** Phpexcel_iofactory*/require_once‘.. /classes/phpexcel/iofactory.php '; //Check Prerequisitesif(!file_exists("31excel5.xls")) {    Exit("Not Found 31excel5.xls.\n");} $reader= Phpexcel_iofactory::createreader (' Excel5 ');//set in EXCEL5 format (excel97-2003 workbook)$PHPExcel=$reader->load ("31excel5.xls");//Loading Excel Files$sheet=$PHPExcel->getsheet (0);//read the first worksheet$highestRow=$sheet->gethighestrow ();//total number of rows obtained$highestColumm=$sheet->gethighestcolumn ();//total number of columns obtained /** Iterate through each cell's data*/ for($row= 1;$row<=$highestRow;$row++){//The number of rows starts at line 1th     for($column= ' A ';$column<=$highestColumm;$column++) {//the number of columns starts with column a        $dataset[] =$sheet->getcell ($column.$row),GetValue (); Echo $column.$row.":".$sheet->getcell ($column.$row)->getvalue (). " <br/> "; }} ?>

Phpexcel reading an Excel file sample

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.