PHP reads the Excel content and writes it to MySQL

Source: Internet
Author: User
Tags html form php write

Implementation features: Upload Excel files and import them into the database according to the format

Find Phpecel on the internet but Phpexcel is too big, its own limited ability is not very good to streamline, finally found phpexcelreader this class; very small and able to achieve the functions I need


First step, download the Phpexcelreader class (given later)

The second step, create add.php write the following code:

$str =$_files[' excelname ' [' tmp_name ']; $data = new Spreadsheet_excel_reader ($STR); $data _arr = $data->sheets; $all _ data = $data _arr[0][' cells '];foreach ($all _data as $ak + = $av) {    Organize SQL statements}
$data->sheets the contents of Excel in the form of data output;

$data->dump (true,true); Output the contents of Excel in HTML form;

Third step, write HTML upload file

<form action= './add ' method= "post" enctype= "Multipart/form-data" > <table cellpadding= ' 5px ' align= ' center ' Width= ' 100% ' > <tr>  <td><span style= ' color:red; ' >*</span> Select files: </td><td><input type= ' file ' name= ' Excelname ' ></td></tr> <TR><TD colspan= ' 2 ' ><input type= ' submit ' name= ' submit ' value= ' Import data ' ></td></tr></ Table></form>
Follow the above process Excel content can be imported into MySQL correctly

Write a good example: http://yun.baidu.com/share/link?shareid=3068641847&uk=2903375990

PHP reads the Excel content and writes it to MySQL

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.