ThinkPHP3.1.3 importing MySQL database from Excel table using phpExcel1.8.0 implementation data

Source: Internet
Author: User

First of all, go to phpexcel official website to download Phpexcel, the official address is http://phpexcel.codeplex.com/. I'm under 1.8.0 version of. After decompression found still pretty big, there are more than 10 m, do not know the other version is not will be small point.

Put the extracted phpexcel files under the thinkphp Vender folder (specifically for third-party libraries), such as

Next, create the Excel transform array class and put it in the Thinkphp\extend\library\org\util directory

Classexceltoarrary {Publicfunction__construct() {Vendor ("PHPExcel.Classes.PHPExcel");Introduce the Phpexcel class (note the path, do not know the path can see the book) Vendor ("PHPExcel.Classes.PHPExcel.IOFactory");Introduce the Phpexcel class (note the path)}PublicfunctionRead($filename,$encode,$file _type) {if (Strtolower ($file _type) = =' XLS ')Determine whether the Excel table type is 2003 or $ {Vendor ("PHPExcel.Classes.PHPExcel.Reader.Excel5");Introducing the Phpexcel class (note the path)$objReader = Phpexcel_iofactory::createreader (' Excel5 '); }ElseIf (Strtolower ($file _type) = =' xlsx ') {Vendor ("PHPExcel.Classes.PHPExcel.Reader.Excel2007");Introducing the Phpexcel class (note the path)$objReader = Phpexcel_iofactory::createreader (' Excel2007 '); }$objReader->setreaddataonly (true);$objPHPExcel =$objReader->load ($FILENAME);$objWorksheet =$objPHPExcel->getactivesheet ();$highestRow =$objWorksheet->gethighestrow ();$highestColumn =$objWorksheet->gethighestcolumn ();$highestColumnIndex = phpexcel_cell::columnindexfromstring ($highestColumn); $excelData = array (); for ( $row = 1;  $row <=  $highestRow;  $row + +) {for ( $col = 0;  $col <  $highestColumnIndex;  $col + +) { $excelData [ $row] = (string)  $objWorksheet->getcellbycolumnandrow ( $col,  $row)->getvalue (); }} return  $excelData;}      
Details Portal: http://blog.csdn.net/walle0513/article/details/47129619

ThinkPHP3.1.3 importing MySQL database from Excel table using phpExcel1.8.0 implementation data

Related Article

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.