Public functionTest () {$exts= ' xlsx '; //Import the Phpexcel class library because Phpexcel does not use a namespace, only inport importImport ("Org.Util.PHPExcel");//Import an Excel Class I'm here to thinkphp framework modification according to its own framework $fileName= "Tel.xls";//Excel file path $objReader= \phpexcel_iofactory::createreader (' Excel5 '); $objPHPExcel=$objReader->load ($fileName,$encode= ' Utf-8 '); $drawing=New\phpexcel_writer_excel2007_drawing (); $drawingHashTable=New\phpexcel_hashtable (); $drawingHashTable->addfromsource ($drawing->alldrawings ($objPHPExcel)); for($i= 0;$i<$drawingHashTable-Count(); ++$i) { $memoryDrawing=$drawingHashTable->getbyindex ($i); if($memoryDrawinginstanceof \phpexcel_worksheet_memorydrawing) { $filename= './public/'.$memoryDrawing->getcoordinates (). ‘_‘ .$memoryDrawing->gethashcode (). '. jpg '; //to save a picture to a specified directoryImagejpeg ($memoryDrawing->getimageresource (),$filename); //get the cell where the picture is located $cell=$memoryDrawing->getworksheet ()->getcell ($memoryDrawing-getcoordinates ()); //set the cell's value to the cell's text plus the IMG label for the Slice $cell->setvalue ($cell->getvalue ().$filename); } } $sheet=$objPHPExcel->getsheet (0); $highestRow=$sheet->gethighestrow ();//total number of rows obtained $highestColumn=$sheet->gethighestcolumn ();//total number of columns obtained for($i= 2;$i<=$highestRow;$i++) { $data[$i[' truename '] =$objPHPExcel->getactivesheet ()->getcell ("A".$i),GetValue (); $data[$i[' Account ']=$objPHPExcel->getactivesheet ()->getcell ("B").$i),GetValue (); $data[$i[' Image '] [] =$objPHPExcel->getactivesheet ()->getcell ("C").$i),GetValue (); $data[$i[' Image '] [] =$objPHPExcel->getactivesheet ()->getcell ("D").$i),GetValue (); $data[$i[' Image '] [] =$objPHPExcel->getactivesheet ()->getcell ("E").$i),GetValue (); } Print_r($data); die; }
PHP reads Excel data into database (contains pictures and text)