php通過PHPExcel導(dǎo)入Excel表格到MySQL數(shù)據(jù)庫的簡單實例
更新時間:2016年10月29日 08:55:04 投稿:jingxian
下面小編就為大家?guī)硪黄猵hp通過PHPExcel導(dǎo)入Excel表格到MySQL數(shù)據(jù)庫的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
如下所示:
<?php define('BASE_URL', realpath(dirname(__FILE__))); require_once BASE_URL . '/PHPExcel/PHPExcel.php';//引入PHPExcel類文件 //excel文件的地址 $excel_fiel_path = './phpexcel.xls'; $PHPExcel = new PHPExcel();// 實例化PHPExcel工具類 //分析文件獲取后綴判斷是2007版本還是2003 $extend = pathinfo("./" . $excel_fiel_path); $extend = strtolower($extend["extension"]); // 判斷xlsx版本,如果是xlsx的就是2007版本的,否則就是2003 if ($extend=="xlsx") { $PHPReader = new PHPExcel_Reader_Excel2007(); $PHPExcel = $PHPReader->load("./" . $excel_fiel_path); }else{ $PHPReader = new PHPExcel_Reader_Excel5(); $PHPExcel = $PHPReader->load("./" . $excel_fiel_path); } /* 第二種方法*/ $objWorksheet = $PHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); echo 'highestRow='.$highestRow; echo "<br>"; $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);//總列數(shù) echo 'highestColumnIndex='.$highestColumnIndex; echo "<br>"; $headtitle=array(); for ($row = 2;$row <= $highestRow;$row++) { $strs=array(); //注意highestColumnIndex的列數(shù)索引從0開始 for ($col = 0;$col < $highestColumnIndex;$col++) { $strs[$col] =$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); } //todo //連接mysql ,一條條寫入 }
以上就是小編為大家?guī)淼膒hp通過PHPExcel導(dǎo)入Excel表格到MySQL數(shù)據(jù)庫的簡單實例全部內(nèi)容了,希望大家多多支持腳本之家~
您可能感興趣的文章:
- 教你使用java將excel數(shù)據(jù)導(dǎo)入MySQL
- 如何將Excel文件導(dǎo)入MySQL數(shù)據(jù)庫
- Springboot上傳excel并將表格數(shù)據(jù)導(dǎo)入或更新mySql數(shù)據(jù)庫的過程
- PHP上傳Excel文件導(dǎo)入數(shù)據(jù)到MySQL數(shù)據(jù)庫示例
- 使用phpexcel類實現(xiàn)excel導(dǎo)入mysql數(shù)據(jù)庫功能(實例代碼)
- php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法
- phpMyAdmin下將Excel中的數(shù)據(jù)導(dǎo)入MySql的圖文方法
- Excel數(shù)據(jù)導(dǎo)入Mysql數(shù)據(jù)庫的實現(xiàn)代碼
- MySQL批量導(dǎo)入Excel數(shù)據(jù)(超詳細)
相關(guān)文章
PHP數(shù)組遍歷知識匯總(包含遍歷方法、數(shù)組指針操作函數(shù)、數(shù)組遍歷測速)
這篇文章主要介紹了PHP數(shù)組遍歷知識匯總,本文包含3種遍歷方法、7個數(shù)組指針操作函數(shù)、對3種數(shù)組遍歷的速度測試等內(nèi)容,需要的朋友可以參考下2014-07-07Zend Framework教程之Application用法實例詳解
這篇文章主要介紹了Zend Framework教程之Application用法,詳細分析了Zend_Application的功能,定義,參數(shù)含義及相關(guān)使用技巧,需要的朋友可以參考下2016-03-03基于PHP+mysql實現(xiàn)新聞發(fā)布系統(tǒng)的開發(fā)
這篇文章主要介紹了基于PHP+mysql實現(xiàn)新聞發(fā)布系統(tǒng)的開發(fā),文章通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下 面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08Laravel5.5 視圖 - 創(chuàng)建視圖和數(shù)據(jù)傳遞示例
今天小編就為大家分享一篇Laravel5.5 視圖 - 創(chuàng)建視圖和數(shù)據(jù)傳遞示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10遍歷echsop的region表形成緩存的程序?qū)嵗a
下面小編就為大家?guī)硪黄闅vechsop的region表形成緩存的程序?qū)嵗a。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11