Reference content is as follows: <? Php Require_onCe 'reader. php '; // ExcelFile ($ filename, $ encoding ); $ DaTa = new Spreadsheet_Excel_Reader (); // Set output Encoding. $ DaTa-> setOutputEncoding ('gbk '); // "DaTa.xls is an excel file to be imported to mysql. $ DaTa-> read ('daTa.xls '); @ $ Db = mysql_connect ('localhost', 'root', '123') or Die ("cocould not connect to database."); // connect to the database Mysql_query ("set names 'gbk'"); // output Chinese Mysql_select_db ('mydb'); // select a database Error_reporting (E_ALL ^ E_NOTICE ); For ($ I = 1; $ I <= $ daTa-> sheets [0] ['numrows ']; $ I ++ ){ // Print the excel table data in a for loop with the following comments /* For ($ j = 1; $ j <= $ daTa-> sheets [0] ['numcols']; $ j ++ ){ Echo "\" ". $ daTa-> sheets [0] ['cells '] [$ I] [$ j]. "\", "; } Echo "\ n "; */ // The following code inserts [3 fields] of the excel table data into mysql. Rewrite the following code based on the number of fields in your excel table! $ 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. '<br/> '; $ Res = mysql_query ($ SQL ); } ?> |