idea One: use an XML file to save a column in Excel from a field in a datasheet, and then add data through an XML file idea two: The first row in Excel saves the field name, and the other rows save the data Three ideas: the column in Excel corresponds to a field in a data table, saved with a. php file here is the idea of two, using the Phpexcel
1. Create an Object
$objReader = Phpexcel_iofactory::createreader (' Excel5 ');//use excel2007 for
2. Specify an Excel file
$objPHPExcel = $objReader->load ($newFileName);
$sheet = $objPHPExcel->getsheet (0); Gets the data that operates the first table in Excel
$highestRow = $sheet->gethighestrow (); Get total number of rows returned to be int type
$highestColumn = $sheet->gethighestcolumn (); Gets the total number of columns returned is the letter
$allFileds = ";
$filedsSum = ' A '; Set the default maximum value for a valid column
$dataInfo = ";
$tidIndex = 0;
for ($i = ' A '; $i < $highestColumn; + + $i) {
$curFiled = $sheet->getcell ($i. ' 1 ')->getvalue ();
if (!empty ($curFiled)) {//Filter invalid columns
$filedsSum = $i;
$allFileds. = ', '. $curFiled. ' `';
}
}
$INPUTDATASQL = "; Inserting SQL statements
for ($j =2; $j <= $highestRow; $j + +) {
$inputData =array ();
for ($i = ' A '; $i <= $filedsSum; + + $i) {
$inputData []= '. $sheet->getcell ($i. $j)->getvalue (). ' \'';
Because you are not sure whether the field is a string or an int type, adding "will not cause an error
$inputDataSql. = ', ('. Implode (', ', $inputData) ') ';
}
$INPUTDATASQL =substr ($INPUTDATASQL, 1); Remove the front one ', ' comma
$sql = ' INSERT into ('. $allFileds. ') VALUES '. $inputDataSql;
Finally, the corresponding database operation object is called and the insert operation is performed.
The above describes the PHP operation Excel file, the Excel data import into the database, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.