Using the Phpexcel class to implement Excel import MySQL database feature instance code mysql database download 64-bit SQL DB instance download SQL database patch Download

Source: Internet
Author: User
Download Phpexcel file, address: phpexcel.codeplex.com/

code example

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 format $objPHPExcel = $objReader->load ($filename); $filename can be an uploaded file, or the specified file $sheet = $objPHPExcel->getsheet (0); $highestRow = $sheet->gethighestrow (); Total number of rows obtained $highestColumn = $sheet->gethighestcolumn (); Total number of columns obtained $k = 0; Iterate through the Excel file, read a line, insert a for ($j =2; $j <= $highestRow; $j + +) {$a = $objPHPExcel->getactivesheet ()->getcell ("a". $J)->getvalue ();//Gets the value of column A $b = $objPHPExcel->getactivesheet ()->getcell ("B". $j)->getvalue ();//Gets the value of column B sql = "INSERT into table VALUES (". $a. ",". $b. ")"; mysql_query ($sql);}

The above this article uses the Phpexcel class to implement the Excel import MySQL database function (instance code) is the small part to share to everybody's entire content, hoped can give everybody a reference, also hoped that everybody supports this station.

The above describes the use of the Phpexcel class to implement Excel import MySQL database function instance code, including the content of MySQL database, I hope to be interested in PHP tutorial friends helpful.

  • 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.