Php import excelphp use phpexcel to import an excel file
// Load the PHPExcel class
- Include (dirname (_ FILE _). '/phpexcel/PHPExcel. php ');
$ Obj = new PHPExcel_Reader_Excel5 ();
- $ Obj-> setReadDataOnly (true );
// Read the demo.xls file
- $ PhpExcel = $ Obj-> load (dirname (_ FILE _). '/output.xls ');
// Obtain the current active sheet
- $ ObjWorksheet = $ phpExcel-> getActiveSheet ();
// Obtain the number of rows
- $ HighestRow = $ objWorksheet-> getHighestRow ();
// Obtain the number of columns
- // By bbs.it-home.org
- $ HighestColumn = $ objWorksheet-> getHighestColumn ();
- $ HighestColumnIndex = PHPExcel_Cell: columnIndexFromString ($ highestColumn );
// Output data cyclically
- $ Data = array ();
- For ($ row = 1; $ row <= $ highestRow; ++ $ row ){
- For ($ col = 0; $ col <$ highestColumnIndex; ++ $ col ){
- $ Val = $ objWorksheet-> getCellByColumnAndRow ($ col, $ row)-> getValue ();
- $ Data [$ row] [$ col] = trim ($ val );
- }
- }
Echo' '; - print_r($data);
- echo '
';
|