欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP 如何利用phpexcel導(dǎo)入數(shù)據(jù)庫(kù)

 更新時(shí)間:2013年08月24日 10:18:15   作者:  
以下是對(duì)PHP中利用phpexcel導(dǎo)入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下
廢話不多說(shuō),直接上代碼吧
復(fù)制代碼 代碼如下:

<?php
error_reporting(E_ALL); //開(kāi)啟錯(cuò)誤
set_time_limit(0); //腳本不超時(shí)

date_default_timezone_set('Europe/London'); //設(shè)置時(shí)間

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'http://www.dbjr.com.cn/../Classes/');//設(shè)置環(huán)境變量

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

//$inputFileType = 'Excel5';    //這個(gè)是讀 xls的
    $inputFileType = 'Excel2007';//這個(gè)是計(jì)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,'<br />';
        $objReader = PHPExcel_IOFactory::createReader($inputFileType);
        $objPHPExcel = $objReader->load($inputFileName);
        /*
        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow(); //取得總行數(shù)
        $highestColumn = $sheet->getHighestColumn(); //取得總列
        */   
        $objWorksheet = $objPHPExcel->getActiveSheet();//取得總行數(shù)
        $highestRow = $objWorksheet->getHighestRow();//取得總列數(shù)

        echo 'highestRow='.$highestRow;
        echo "<br>";
        $highestColumn = $objWorksheet->getHighestColumn();
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//總列數(shù)
        echo 'highestColumnIndex='.$highestColumnIndex;
        echo "<br />";
        $headtitle=array();
        for ($row = 1;$row <= $highestRow;$row++)
        {
            $strs=array();
            //注意highestColumnIndex的列數(shù)索引從0開(kāi)始
            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]",
              );
              //在這兒,你可以連接,你的數(shù)據(jù)庫(kù),寫(xiě)入數(shù)據(jù)庫(kù)了
              print_r($info);
              echo '<br />';
        }
?>

相關(guān)文章

最新評(píng)論