Use phpexcel to import mysql database (instance code) _ php instance

Source: Internet
Author: User
The following section describes how to use the phpexcel class to import mysql databases to excel (instance code ). I think it is quite good. Now I will share it with you and give you a reference. Let's take a look at the phpexcel file. Address: phpexcel.codeplex.com/

Sample Code

Require_once 'phpexcel/Classes/phpexcel. php '; require_once' phpexcel/Classes/PHPExcel/IOFactory. php '; require_once 'phpexcel/Classes/phpexcel/Reader/excel5.php'; $ objReader = PHPExcel_IOFactory: createReader ('excel5 '); // use excel2007 for 2007 format $ objPHPExcel = $ objReader-> load ($ filename); // $ filename can be an uploaded file, or the specified file $ sheet = $ objPHPExcel-> getSheet (0); $ highestRow = $ sheet-> getHighestRow (); // get the total number of rows $ highestColumn = $ sheet-> getHighestColumn (); // get the total number of columns $ k = 0; // read the excel file cyclically and read one, insert a for ($ j = 2; $ j <= $ highestRow; $ j ++) {$ A = $ objPHPExcel-> getActiveSheet ()-> getCell ("". $ j)-> getValue (); // obtain the value of column A $ B = $ objPHPExcel-> getActiveSheet ()-> getCell ("B ". $ j)-> getValue (); // obtain the value of Column B $ SQL = "INSERT INTO table VALUES (". $. ",". $ B. ")"; mysql_query ($ SQL );}

In the above section, using phpexcel to import mysql databases (instance Code) is all the content that I have shared with you. I hope you can provide a reference and support for me.

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.