Last night a customer contacted me to do the site, the request is to be provided by the customer's Excel file inside the data into the MySQL database, the most common way is to first export the XLS file into a CSV format file, and then in the resolution CSV format file import into the MySQL database. Method compared redundancy, and divided into several steps, very inconvenient, broken bridge today a method is to skip the intermediate link of CSV directly, import Excel file into MySQL database.
First we need to download Php-excelreader This is an open source project, mainly to parse Excel file, download address: http://sourceforge.net/projects/phpexcelreader, unzip after download, The main use of the Excel folder inside the two files reader.php and oleread.php (this file default is Oleread.inc, not clear why, a bunch of e-wen, did not see, directly renamed can be).
Find the following similar code in the reader.php file (the first line is both), change to the correct oleread.php path: require_once ' oleread.php ';
Then create a new PHP file to introduce reader.php with the following code:
Require_once ' excel/reader.php ';
$data = new Spreadsheet_excel_reader ();
$data->setoutputencoding (' GBK '); \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GBK
$data->read (' Book1.xls ');//file path
Error_reporting (e_all ^ e_notice);
Here I just loop out the contents of the Excel file, to the storage, as long as the output of the place, write a MySQL sentence can ~
for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) {
for ($j = 1; $j <= $data->sheets[0][' numcols '); $j + +) {
echo "\" ". $data->sheets[0][' cells ' [$i] [$j]." \",";
}
echo "\ n";
}
?>
Note: Please do not use the Php-excelreader compression package inside the XLS test, broken snow found that the file is not only using Excel can not open, so it is wrong.
Broken Bridge using the above method to resolve a 1.4M data, are displayed normal, so you can rest assured that the use of
Original: http://www.js8.in/618.html
http://www.bkjia.com/PHPjc/364687.html www.bkjia.com true http://www.bkjia.com/PHPjc/364687.html techarticle last night a customer contacted me to do the site, the request is to be provided by the customer Excel file inside the data into the MySQL database, the most common method is to first export the XLS file as ...