Talking about PHP import Excel file
There are several open source files for PHP to import into Excel, and I use Phpexcelreader.
Here's how to go directly to the code:
$filename = $_files [' Excel '] [' name ']; $tmp _name = $_files [' Excel '] [' tmp_name '];//Save the upload file if (move_uploaded_file ($tmp _n Ame, ' upload/'. $filename)) { inputexcel ($filename);} Call readerrequire_once ' reader.php ';//create reader$data = new Spreadsheet_excel_reader ();//Set Text output encoding $data-> Setoutputencoding (' utf-8 ');//Read Excel file $data->read (' upload/'. $filename);//$data->sheets[0][' numrows '] Number of lines for Excel//$data->sheets[0][' numcols '] for Excel columns for ($i = 2; $i <= $data->sheets[0][' numrows '); $i + +) { //from single Get data $a prompt = mysql_real_escape_string ($data->sheets [0] [' cells '] [$i] [1]); $b = mysql_real_escape_string ($data->sheets [0] [' cells '] [$i] [2]); $c = mysql_real_escape_string ($data->sheets [0] [' cells '] [$i] [3]); $d = mysql_real_escape_string ($data->sheets [0] [' cells '] [$i] [4]);}
?
The function of this code is to upload an Excel file and get the data, it is worth explaining:
1, the Excel table does not have half-width (parentheses) and [brackets], because it gets the data is directly saved to an array, so that the (parentheses) and [brackets] will affect the format of the array, and raise an error, I would rather replace them with the perfect angle (parentheses) and "brackets."
2, if you want to remove the value from Excel and the database interaction, I here mysql_real_escape_string (data) directly escaped, to prevent the execution of the database because of some symbols caused by errors.
3, when the amount of data in Excel is large, when inserting into the database, note the length of the SQL statement, the length of the PHP string is limited to the configuration in php.ini and computer memory.
4, $data->setoutputencoding (' utf-8 ') can solve the problem of Chinese garbled.
?