PHP Import Excel Collection
PHP Import into Excel
PHP-excelreader,DownloadAddress: Http://sourceforge.net/projects/phpexcelreader
Description Test environment: MYSQLDatabaseUse UTF8 encoding. The import Excel document is in XLS format, tested, and the XLSX format [Excel 2007] is OK. In the text, please note that the Red label should be replaced by your configuredData, such as database configuration. Run http://localost/test.php to implement the import. Here are the details I postedCode, where Test.php wrote the test for mefile, the reader.php and oleread.inc files are downloaded from the URLs provided above. After downloading, please change the call according to the actual situationPathInclude reader.php call Oleread.inc 1.?? test.php
Require_once ' reader.php ';
Excelfile ($filename, $encoding); $data = new Spreadsheet_excel_reader ();
Set output Encoding. $data->setoutputencoding (' GBK ');
"Data.xls" means an Excel file to import into MySQL $data->read (' Data.xls ');
@ $db = mysql_connect (' localhost ', ' root ', ' 123456 ') or ? ?? ? Die ("Could not connect to database."); /Connection Database mysql_query ("Set names ' GBK '");//OutputChinese mysql_select_db (' mydb ');? ?? ? Select Database Error_reporting (e_all ^ e_notice);
for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) { The For loop of the following comments prints the Excel table data /* for ($j = 1; $j <= $data->sheets[0][' numcols '); $j + +) { ? ?? ?? ?? echo "\" ". $data->sheets[0][' cells ' [$i] [$j]." \","; ? ?? ?? ???} ? ?? ?? ??? echo "\ n"; */ The following code is to insert the Excel table Data "3 fields" into MySQL, according to the number of your Excel table field, rewrite the following code! ? ? $sql = "INSERT into Test VALUES ('". ? ?? ?? ?? ?? ? $data->sheets[0][' cells ' [$i][1]. "', '". ? ?? ?? ?? ?? ??? $data->sheets[0][' cells ' [$i][2]. "', '". ? ?? ?? ?? ?? ??? $data->sheets[0][' cells '] [$i][3]. "')"; ? ? echo $sql. ' '; ? ?? ? $res = mysql_query ($sql); }
?> |
PHP-excelreader,DownloadAddress: Http://sourceforge.net/projects/phpexcelreader
Description Test environment: MYSQLDatabaseUse UTF8 encoding. The import Excel document is in XLS format, tested, and the XLSX format [Excel 2007] is OK. In the text, please note that the Red label should be replaced by your configuredData, such as database configuration. Run http://localost/test.php to implement the import. Here are the details I postedCode, where Test.php wrote the test for mefile, the reader.php and oleread.inc files are downloaded from the URLs provided above. After downloading, please change the call according to the actual situationPathInclude reader.php call Oleread.inc 1.?? test.php
Require_once ' reader.php ';
Excelfile ($filename, $encoding); $data = new Spreadsheet_excel_reader ();
Set output Encoding. $data->setoutputencoding (' GBK ');
"Data.xls" means an Excel file to import into MySQL $data->read (' Data.xls ');
@ $db = mysql_connect (' localhost ', ' root ', ' 123456 ') or ? ?? ? Die ("Could not connect to database."); /Connection Database mysql_query ("Set names ' GBK '");//OutputChinese mysql_select_db (' mydb ');? ?? ? Select Database Error_reporting (e_all ^ e_notice);
for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) { The For loop of the following comments prints the Excel table data /* for ($j = 1; $j <= $data->sheets[0][' numcols '); $j + +) { ? ?? ?? ?? echo "\" ". $data->sheets[0][' cells ' [$i] [$j]." \","; ? ?? ?? ???} ? ?? ?? ??? echo "\ n"; */ The following code is to insert the Excel table Data "3 fields" into MySQL, according to the number of your Excel table field, rewrite the following code! ? ? $sql = "INSERT into Test VALUES ('". ? ?? ?? ?? ?? ? $data->sheets[0][' cells ' [$i][1]. "', '". ? ?? ?? ?? ?? ??? $data->sheets[0][' cells ' [$i][2]. "', '". ? ?? ?? ?? ?? ??? $data->sheets[0][' cells '] [$i][3]. "')"; ? ? echo $sql. ' '; ? ?? ? $res = mysql_query ($sql); }
?> |