One. Import
Import needs to use the components that can read Excel, there are better components on the net, here to share I use: Download extract code: Vxyn. (Note that two files have a citation relationship)
Setoutputencoding (' Utf-8 '); Sets the character encoding output after reading the contents of Excel $data->read ("data/excel/{$filename}.xls"); $db = mysql_connect (' localhost ', ' username ', ' password ') or Die ("Could does connect to database."); Connect database mysql_query ("Set names ' Uft8 '");//Output Chinese mysql_select_db (' database name ');//Select Database error_reporting (e_all ^ e_notice); for ($i = 1; $i <= $data->sheets[0][' numrows '); $i + +) { echo $data->sheets[0][' cells '] [$i] [Number of columns]; Here you can insert the value of the corresponding column of each row into the database, such as:/ * $sql = "Insert" Table name "values (corresponding items ...)"; mysql_query ($sql); Can be wrongly judged */ } ?>
In short, you can read the values of the corresponding column $data->sheets[0][[column] in each row in the table, and the insert operation will be done.
Two. Export
Export can easily export tabular files without relying on any components using the HTTP protocol. You can export Excel by setting the header in the following format, while the browser downloads
Header (' content-type:text/html; charset=utf-8 '); Header ("Content-type:application/vnd.ms-excel;charset=utf-8"); APPLICATION/VND.MS-EXCEL specifies the output Excel format header ("content-disposition:filename= table file name. xls"); Table name of the output
The complete code is as follows:
In fact, \ t is a change of grid, \ nthe line. Set up a link to this PHP file in a Web page, and the browser will automatically save the streamed stream as an Excel file when clicked.