Home  >  Article  >  Backend Development  >  PHP How to use phpexcel to import database_PHP tutorial

PHP How to use phpexcel to import database_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:59:07872browse

Without further ado, let’s go straight to the code

Copy the code The code is as follows:

error_reporting( E_ALL); //Open error
set_time_limit(0); //Script does not timeout

date_default_timezone_set('Europe/London'); //Set 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 for reading xls
$inputFileType = 'Excel2007';//This is
//$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);
                                                                  Get the total number of rows
$highestColumn = $sheet->getHighestColumn(); //Get the total rows
*/
$objWorksheet = $objPHPExcel->getActiveSheet(); //Get the total rows
        $highestRow = $objWorksheet->getHighestRow();//Get the total number of columns

                                                                   $highestRow =                                                  $highestRow                                                                                            $highestRow =      = $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();
                                                                                                                                           =$objWorksheet ->getCellByColumnAndRow($col, $row)->getValue();
                                                                                                     🎜> 'word2'=>"$strs[1]",
'word3'=>"$strs[2]",
'word4'=>"$strs[3]",
               ); }
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328157.htmlTechArticle Without further ado, let’s go directly to the code. Copy the code as follows: ?php error_reporting(E_ALL); //Open Error set_time_limit(0); //The script does not timeout date_default_timezone_set('Europe/Lo...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn