PHP uses phpexcel to import data to a database. If you don't talk about it, simply copy the code as follows :? Phperror_reporting (E_ALL); enable set_time_limit (0); script does not time out date_default_timezone_set
The code is as follows:
Error_reporting (E_ALL); // An error occurred while enabling
Set_time_limit (0); // The script does not time out.
Date_default_timezone_set ('Europe/London '); // Set the time
/** Include path **/
Set_include_path (get_include_path (). PATH_SEPARATOR. 'http: // www.jb51.net/./classes/'); // Set the environment variable
/** PHPExcel_IOFactory */
Include 'phpexcel/IOFactory. php ';
// $ InputFileType = 'excel5'; // read the xls
$ InputFileType = 'excel2007 '; // This is the xlsx
// $ InputFileName = './sampleData/example2.xls ';
$ InputFileName = './sampleData/book.xlsx ';
Echo 'loading file', pathinfo ($ inputFileName, PATHINFO_BASENAME), 'using IOFactory with a defined reader type of ', $ inputFileType ,'
';
$ ObjReader = PHPExcel_IOFactory: createReader ($ inputFileType );
$ ObjPHPExcel = $ objReader-> load ($ inputFileName );
/*
$ Sheet = $ objPHPExcel-> getSheet (0 );
$ HighestRow = $ sheet-> getHighestRow (); // gets the total number of rows.
$ HighestColumn = $ sheet-> getHighestColumn (); // get the total column
*/
$ ObjWorksheet = $ objPHPExcel-> getActiveSheet (); // get the total number of rows
$ HighestRow = $ objWorksheet-> getHighestRow (); // gets the total number of columns
Echo 'hehestrow = '. $ highestRow;
Echo"
";
$ HighestColumn = $ objWorksheet-> getHighestColumn ();
$ HighestColumnIndex = PHPExcel_Cell: columnIndexFromString ($ highestColumn); // The total number of columns
Echo 'hehestcolumnindex = '. $ highestColumnIndex;
Echo"
";
$ Headtitle = array ();
For ($ row = 1; $ row <= $ highestRow; $ row ++)
{
$ Strs = array ();
// Note that the index of the highestColumnIndex column starts from 0.
For ($ col = 0; $ col <$ highestColumnIndex; $ col ++)
{
$ Strs [$ col] = $ objWorksheet-> getCellByColumnAndRow ($ col, $ row)-> getValue ();
}
$ Info = array (
'Word1 '=> "$ strs [0]",
'Word2 '=> "$ strs [1]",
'Word3 '=> "$ strs [2]",
'Word4' => "$ strs [3]",
);
// You can connect to your database and write it to the database.
Print_r ($ info );
Echo'
';
}
?>
The pipeline code is as follows :? Php error_reporting (E_ALL); // The error set_time_limit (0) is enabled; // The script does not time out. date_default_timezone_set ('Europe/Lo...