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