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