Sometimes we just need to read some of the specified sheet, with the following code:
<?PHPHeader("Content-type:text/html;charset=utf-8");//Introduction to Reading Excel class filesrequire"./phpexcel/phpexcel/iofactory.php";$fileName= "./class.xlsx";//get the type of file$fileType= Phpexcel_iofactory::identify ($fileName);//This example outputs excel2007//to get a file read operation object$objReader= Phpexcel_iofactory::createreader ($fileType);$sheetName=Array("Grade 2", "Grade 3");//Specify sheet name$objReader->setloadsheetsonly ($sheetName);//Specifies the loaded sheet$objPHPExcel=$objReader->load ($fileName);//loop to get sheet data, using Phpexcel's own iteratorforeach($objPHPExcel->getworksheetiterator () as $sheet) { foreach($sheet->getrowiterator () as $row){//reading data row by line if($row->getrowindex () < 2) { Continue;//Read only from the second row, omitting the title } foreach($row->getcelliterator () as $cell) {//reading data columns by column $data=$cell->getvalue ();//Get Cell data Echo $data." "; } Echo' <br> '; } Echo' <br> ';}
The above lists only data for grades 2 and 3.
PHP read Excel (6)