How PHP uses Phpexcel to import a database _php tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.