Php-excelreader,: http://sourceforge.net/projects/phpexcelreader
Note the point :
The following line in the reader.php to be modified
1, will require_once ' spreadsheet/excel/reader/oleread.php '; instead of require_once ' oleread.inc ';
2, require_once ' Oleread.inc ' can also be copied out to the reader in front of the file merged into a file
3. $data->setoutputencoding (' Utf-8 ') can also be used in this way, my project is Utf-8 coding, began to use the above writing $data->setoutputencoding (' cp936′ '); As a result, the import database always says coding errors. Finally set up to Utf-8 solved.
Upload Excel Interface code:
upexcel.php
<?phpheader ("Content-type:text/html;charset=utf-8"); Set font encoding to avoid Chinese garbled characters? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Implementing code that uploads to the database insert.php<? Phpheader ("Content-type:text/html;charset=utf-8"); Set the font encoding to avoid Chinese garbled require_once (".. /db_config.php "); require_once ' excel/reader.php '; Error_reporting (e_all ^ e_notice); Ini_set (' max_execution_time ', ' 100 '); PHP runs for 30 seconds, and when the amount of data is large, a time-out occurs that prevents all imports. if ($_post) {$Import _tmpfile = $_files[' file '] [' tmp_name '];//$Import _tmpfile = ' http:// Test998-merchphoto.stor.sinaapp.com/test.xls '; $data = new Spreadsheet_excel_reader (); $data->setoutputencoding (' utf-8 '); $data->read ($Import _tmpfile); $count = 0; for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) {$sql = "INSERT into Test_xls (id,tm,name) VALUES ('". $data->sheets[0][' cells ' [$i][1]. "', '". $data->sheets[0][' cells ' [$i][2]. "', '". $data->sheets[0][' cells '] [$i][3]. "')"; echo $sql. " </br> "; if (mysql_query ($sql)) {$count + +;}} echo "<script>alert (' successful import '). $count." Data ');</script> "; }?>
MySQL table:
Excel:
Resources:
1, http://jason2016.blog.51cto.com/892969/289411
2, http://www.cnblogs.com/phpzxh/archive/2009/09/16/1568133.html
3, http://blog.csdn.net/china_skag/article/details/7098473
Php method for importing Excel to MySQL