First, thinkphp introduced Phpexcel to/thinkphp/library/vendor/
Second, reference in the controller
Public Function Get_detail () { Vendor ("Phpexcel.phpexcel", "', '. php '); $obj = new \phpexcel; $filename = self::file_dir. ' My_data.xls '; try { $inputFileType = \phpexcel_iofactory::identify ($filename); $objReader = \phpexcel_iofactory::createreader ($inputFileType); $objPHPExcel = $objReader->load ($filename); } catch (Exception $e) {die (' Loading file error: '. PathInfo ($filename, Pathinfo_basename). ': '. $e->getmessage ()); } $sheet = $objPHPExcel->getsheet (0); $highestRow = $sheet->gethighestrow (); $highestColumn = $sheet->gethighestcolumn (); for ($i =1; $i <= $highestRow; $i + +) { $rowData [] = $sheet->rangetoarray ("a{$i}:{$highestColumn} {$i}", NULL, True,false); } echo Json_encode ($rowData); }
For the first time in use, encountered some pits, sharing the next
1.Vendor ("Phpexcel.phpexcel", "', '. php '), can be Vendor (" Phpexcel.phpexcel "); Suffix is subject to availability
2. To attach great importance to namespace issues, be sure to add a backslash ' \
‘
thinkphp Operation Phpexcel Problem