No more nonsense, just go to the code.
Copy CodeThe code is as follows:
Error_reporting (E_all); Open error
Set_time_limit (0); 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 environment variables
/** Phpexcel_iofactory */
Include ' phpexcel/iofactory.php ';
$inputFileType = ' Excel5 '; This is read 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 ', $inputFi Letype, '
';
$objReader = Phpexcel_iofactory::createreader ($inputFileType);
$objPHPExcel = $objReader->load ($inputFileName);
/*
$sheet = $objPHPExcel->getsheet (0);
$highestRow = $sheet->gethighestrow (); Total number of rows obtained
$highestColumn = $sheet->gethighestcolumn (); Get Total column
*/
$objWorksheet = $objPHPExcel->getactivesheet ();//Get Total rows
$highestRow = $objWorksheet->gethighestrow ();//Get total number of columns
Echo ' highestrow= '. $highestRow;
echo "
";
$highestColumn = $objWorksheet->gethighestcolumn ();
$highestColumnIndex = phpexcel_cell::columnindexfromstring ($highestColumn);//Total number of columns
Echo ' highestcolumnindex= '. $highestColumnIndex;
echo "
";
$headtitle =array ();
for ($row = 1; $row <= $highestRow; $row + +)
{
$strs =array ();
Note the number of columns in the Highestcolumnindex index starts at 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] ',
);
Here, you can connect, your database, write to the database.
Print_r ($info);
Echo '
';
}
?>
http://www.bkjia.com/PHPjc/328157.html www.bkjia.com true http://www.bkjia.com/PHPjc/328157.html techarticle no more nonsense, just on the code. Copy the code as follows: PHP error_reporting (E_all);///Turn On Error set_time_limit (0);//script does not time out Date_default_timezone_set (' Europe/lo ...