Simple example of PHP importing Excel form to MySQL database via Phpexcel

Source: Internet
Author: User
The above is the whole content of this article PHP through the Phpexcel import Excel table to MySQL database Simple example, I hope that everyone's learning is helpful. Related recommendations:

As shown below:

<?phpdefine (' Base_url ', Realpath (dirname (__file__))); Require_once Base_url. '/phpexcel/phpexcel.php ';//The address of the//excel file that introduced the Phpexcel class file $excel_fiel_path = './phpexcel.xls '; $PHPExcel = new Phpexcel () ;//Instantiate Phpexcel Tool class//parse file gets the suffix to determine whether it is version 2007 or 2003$extend = PathInfo ("./". $excel _fiel_path); $extend = Strtolower ($extend [" Extension "]);  Determine the xlsx version, if it is the 2007 version of XLSX, otherwise it is 2003if ($extend = = "xlsx") {$PHPReader = new phpexcel_reader_excel2007 (); $PHPExcel = $PHPReader->load ("./". $excel _fiel_path);}  else{$PHPReader = new Phpexcel_reader_excel5 (); $PHPExcel = $PHPReader->load ("./". $excel _fiel_path);} /* The second method */$objWorksheet = $PHPExcel->getactivesheet (); $highestRow = $objWorksheet->gethighestrow (); Echo ' highestrow= '. $highestRow; echo "<br>" $highestColumn = $objWorksheet->gethighestcolumn (); $ Highestcolumnindex = phpexcel_cell::columnindexfromstring ($highestColumn);//Total number of columns echo ' highestcolumnindex= '. $ Highestcolumnindex;echo "<br>"; $headtitle =array (); for ($row = 2; $row <= $highestRow, $row + +) {$strs =array (); Note that the number of columns in the Highestcolumnindex index starts at 0 for ($col = 0; $col < $highestColumnIndex; $col + +) {$strs [$col] = $objWorksheet  Getcellbycolumnandrow ($col, $row)->getvalue (); }//todo//Connect MySQL, write}

The above is the whole content of this article, I hope that everyone's study has helped.


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.