Example: 1. Import only one sheets Excel file Require_once ("db.php"); Reference database instantiation class require_once ("reader.php"); Apply a class that imports Excel $data = new Spreadsheet_excel_reader (); Instantiate class $data->setoutputencoding (' utf-8 ');//Set Encoding $data->read ($_files["Excel" ["Tmp_name"]);//Read Excel temp file if ( $data->sheets[0][' numrows ']>0) {//Determine if the number of lines in Excel is greater than 0 lines $data->sheets[0][' NumRows ') is the total number of rows for Excel ($i = 2; $i <= $data->sheets[0][' numrows ']; $i + +) {//EXECL data is inserted into the database $i means reading from the $i line of Excel $sql = "INSERT INTO ' user ' (' user_name ', ' phone ', ' user_email ', ' password ') Values (' {$data->sheets[0][' cells ' [$i][1]} ',//$i is the line number in Excel ' {$data->sheets[0][' cells '] [$i][2]} ', ' {$data- >sheets[0][' cells '] [$i][3]} ', ' 123456 '); $db->query ($sql); }} 2 Import an Excel file that has multiple sheets in fact and import a sheets is the same if there are two sheets (and so on) require_once ("db.php"); Reference database instantiation class require_once ("reader.php"); Apply a class that imports Excel $data = new Spreadsheet_excel_reader (); Instantiate class $data->setoutputencoding (' utf-8 ');//Set Encoding $data->read ($_files["Excel" ["Tmp_name"]);//Read excEl temp file if ($data->sheets[0][' numrows ']>0) {//Determine if the number of lines in Excel is greater than 0 lines $data->sheets[0][' NumRows '] is the total number of Excel rows here $data->sheets[0] Represents the first sheets in Excel for ($i = 2; $i <= $data->sheets[0][' numrows '); $i + +) {//Inserts EXECL data into the database $i represents the E Xcel Line $i starts reading $sql = "INSERT INTO ' user ' (' user_name ', ' phone ', ' user_email ', ' Password ') values (' {$data->sheets[0][') Cells ' [$i][1]} ',//$i is the line number in Excel ' {$data->sheets[0][' cells '] [$i][2]} ', ' {$data->sheets[0][' cells ' [$i][3]} ' , ' 123456 ') "; $db->query ($sql); if ($data->sheets[1][' numrows ']>0) {//To determine if the number of lines in Excel is greater than 0 lines $data->sheets[0][' NumRows '] is the total number of Excel rows here Data->sheets[1] Represents the second sheets for ($i = 2; $i <= $data->sheets[1][' numrows '); $i + +) {//Inserts EXECL data into the database $i represents the $ from Excel I line starts reading $sql = "INSERT INTO ' user ' (' user_name ', ' phone ', ' user_email ', ' Password ') values (' {$data->sheets[1][' cells ') [$i] [1]} ',//$i is the line number in Excel ' {$data->sheets[1][' cells ' [$i][2]} ', ' {$data->sheets[1][' cells '] [$i][3]} ', ' 123456 ') " ; $db->query ($sql); } }
http://www.bkjia.com/PHPjc/477132.html www.bkjia.com true http://www.bkjia.com/PHPjc/477132.html techarticle Example: 1. Import only one sheets Excel file require_once (db.php);//reference DB Instantiation Class require_once (reader.php);//Apply import to Excel class $data = new Sp Readsheet ...