Php excel-php Tutorial

Source: Internet
Author: User
PHP excel code for importing an excel file to a database
In this article, PHP uses phpexcel to import database code. if you are interested in phpexcel, it is good to give a reference.

Phpexcel imports the content to the database. the code is as follows:

     '; $ ObjReader = PHPExcel_IOFactory: createReader ($ inputFileType); $ objPHPExcel = $ objReader-> load ($ inputFileName ); /* $ sheet = $ objPHPExcel-> getSheet (0); $ highestRow = $ sheet-> getHighestRow (); // get the total number of rows $ highestColumn = $ sheet-> getHighestColumn (); // get the total number of columns */$ objWorksheet = $ objPHPExcel-> getActiveSheet (); // obtain the total number of rows $ highestRow = $ objWorksheet-> getHighestRow (); // obtain the total number of columns echo 'highestrow = '. $ highestRow; echo"
"; $ HighestColumn = $ objWorksheet-> getHighestColumn (); $ highestColumnIndex = PHPExcel_Cell: columnIndexFromString ($ highestColumn"
"; $ Headtitle = array (); for ($ row = 1; $ row <= $ highestRow; $ row ++) {$ strs = array (); // note that the index of the highestColumnIndex column starts from 0 for ($ col = 0; $ col <$ highestColumnIndex; $ col ++) {$ strs [$ col] = $ objWorksheet-> getCellByColumnAndRow ($ col, $ row)-> getValue ();} $ info = array ('word1 '=> "$ strs [0]", 'word2' => "$ strs [1]", 'word3 '=> "$ strs [2]", 'word4' => "$ strs [3]",); // code can be placed in the reference, write data to the database print_r ($ info); echo'
';}?>

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.