PHP reads Excel data into database (contains pictures and text)

Source: Internet
Author: User

 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.