最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php讀取EXCEL文件 php excelreader讀取excel文件

 更新時間:2012年12月06日 11:11:46   作者:  
php開發(fā)中肯定會遇到將excel文件內(nèi)容導(dǎo)入到數(shù)據(jù)庫的需要,php-excel-reader可以很輕松的使用它讀取excel文件,本文將詳細介紹,需要了解的朋友可以參考下

php開發(fā)中肯定會遇到將excel文件內(nèi)容導(dǎo)入到數(shù)據(jù)庫的需要,php-excel-reader是一個讀取excel的類,可以很輕松的使用它讀取excel文件非常方便。

php-excel-reader下載地址: http://m.fzitv.net/codes/67223.html

我下載的是php-excel-reader-2.21版本,使用的時候還遇到幾個小問題,后面再細說,先奉上php實例:

我使用的excel如下圖:

php-excel-readerphp代碼如下:

復(fù)制代碼 代碼如下:

<?php
/*by www.phpddt.com*/
header("Content-Type:text/html;charset=utf-8");
require_once 'excel_reader2.php';
//創(chuàng)建對象
$data = new Spreadsheet_Excel_Reader();
//設(shè)置文本輸出編碼
$data->setOutputEncoding('UTF-8');
//讀取Excel文件
$data->read("example.xls");
//$data->sheets[0]['numRows']為Excel行數(shù)
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
//$data->sheets[0]['numCols']為Excel列數(shù)
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
//顯示每個單元格內(nèi)容
echo $data->sheets[0]['cells'][$i][$j].' ';
}
echo '<br>';
}
?>

讀取結(jié)果截圖如下

php-excel-reader讀取excel文件再來說說這個類的小問題:

(1)出現(xiàn)Deprecated: Function split() is deprecated in 。。。錯誤

解決:將excel_reader2.php源碼中split改為explode,詳情點擊php中explode與split的區(qū)別介紹

(2)出現(xiàn)Deprecated: Assigning the return value of new by reference is deprecated in錯誤

解決:將excel_reader2.php源碼中$this->_ole =& new OLERead()中 &去掉,因為php5.3中廢除了=& 符號直接用=引用

(3)亂碼問題解決:

構(gòu)造函數(shù)是function Spreadsheet_Excel_Reader($file='',$store_extended_info=true,$outputEncoding=''),它默認的編碼是utf-8,如果不指定,可能會出現(xiàn)亂碼問題,可通過$data->setOutputEncoding('GBK');指定,還有如果你使用dump()函數(shù),dump()函數(shù)將excel內(nèi)容一html格式輸出,使用htmlentities將字符轉(zhuǎn)化為html的,它默認使用ISO8559-1編碼的,所以你要將 excel_reader2.php源碼中 htmlentities($val)函數(shù)改為htmlentities($val,ENT_COMPAT,"GB2312");才行。

最后來說說,php-excel-reader操作excel中的兩個重要的方法

1.dump(),它可以將excel內(nèi)容以html格式輸出:

echo $data->dump(true,true);

2.將excel數(shù)據(jù)存入數(shù)組中,使用$data->sheets,打印下如下:

復(fù)制代碼 代碼如下:

Array
(
[0] => Array
(
[maxrow] => 0
[maxcol] => 0
[numRows] => 5
[numCols] => 4
[cells] => Array
(
[1] => Array
(
[1] => 編號
[2] => 姓名
[3] => 年齡
[4] => 學(xué)號
)
[2] => Array
(
[1] => 1
[2] => 小紅
[3] => 22
[4] => a1000
)
[3] => Array
(
[1] => 2
[2] => 小王
[3] => 33
[4] => a1001
)
[4] => Array
(
[1] => 3
[2] => 小黑
[3] => 44
[4] => a1002
)
[5] => Array
(
[2] => by
[3] => www.phpddt.com
)
)
[cellsInfo] => Array
(
[1] => Array
(
[1] => Array
(
[xfIndex] => 15
)
[2] => Array
(
[xfIndex] => 15
)
[3] => Array
(
[xfIndex] => 15
)
[4] => Array
(
[xfIndex] => 15
)
)
[2] => Array
(
[1] => Array
(
[string] => 1
[raw] => 1
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 0
[formatColor] =>
[xfIndex] => 15
)
[2] => Array
(
[xfIndex] => 15
)
[3] => Array
(
[string] => 22
[raw] => 22
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 0
[formatColor] =>
[xfIndex] => 15
)
[4] => Array
(
[xfIndex] => 15
)
)
[3] => Array
(
[1] => Array
(
[string] => 2
[raw] => 2
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 6
[formatColor] =>
[xfIndex] => 23
)
[2] => Array
(
[xfIndex] => 23
)
[3] => Array
(
[string] => 33
[raw] => 33
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 6
[formatColor] =>
[xfIndex] => 23
)
[4] => Array
(
[xfIndex] => 23
)
)
[4] => Array
(
[1] => Array
(
[string] => 3
[raw] => 3
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 0
[formatColor] =>
[xfIndex] => 15
)
[2] => Array
(
[xfIndex] => 15
)
[3] => Array
(
[string] => 44
[raw] => 44
[rectype] => unknown
[format] => %s
[formatIndex] => 0
[fontIndex] => 0
[formatColor] =>
[xfIndex] => 15
)
[4] => Array
(
[xfIndex] => 15
)
)
[5] => Array
(
[2] => Array
(
[xfIndex] => 15
)
[3] => Array
(
[xfIndex] => 24
[hyperlink] => Array
(
[flags] => 23
[desc] => www.phpddt.com
[link] => http://www.phpddt.co
)
)
)
)
)
[1] => Array
(
[maxrow] => 0
[maxcol] => 0
[numRows] => 0
[numCols] => 0
)
[2] => Array
(
[maxrow] => 0
[maxcol] => 0
[numRows] => 0
[numCols] => 0
)
)

這樣你應(yīng)該知道怎么取excel中的數(shù)據(jù)了,好了,使用php-excel-reader讀取excel文件就是這么簡單

相關(guān)文章

  • PHP上傳文件及圖片到七牛的方法

    PHP上傳文件及圖片到七牛的方法

    這篇文章主要介紹了PHP上傳文件及圖片到七牛的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • PHP MySql增刪改查的簡單實例

    PHP MySql增刪改查的簡單實例

    下面小編就為大家?guī)硪黄狿HP MySql增刪改查的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • Thinkphp 框架擴展之類庫擴展操作詳解

    Thinkphp 框架擴展之類庫擴展操作詳解

    這篇文章主要介紹了Thinkphp 框架擴展之類庫擴展操作,結(jié)合實例形式分析了Thinkphp 類庫擴展的相關(guān)原理、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下
    2020-04-04
  • 基于Snoopy的PHP近似完美獲取網(wǎng)站編碼的代碼

    基于Snoopy的PHP近似完美獲取網(wǎng)站編碼的代碼

    基于Snoopy的PHP近似完美獲取網(wǎng)站編碼 用于php爬蟲,獲取編碼準(zhǔn)確率99.9%, 還有部分不能獲取,求大牛完善
    2011-10-10
  • PHP正則表達式過濾html標(biāo)簽屬性(DEMO)

    PHP正則表達式過濾html標(biāo)簽屬性(DEMO)

    這篇文章主要介紹了PHP正則表達式過濾html標(biāo)簽屬性的相關(guān)內(nèi)容,實用性非常,感興趣的朋友參考下吧
    2016-05-05
  • 開啟PHP的偽靜態(tài)模式

    開啟PHP的偽靜態(tài)模式

    偽靜態(tài)又名URL重寫,是動態(tài)的網(wǎng)址看起來像靜態(tài)的網(wǎng)址。換句話說就是,動態(tài)網(wǎng)頁通過重寫 URL 方法實現(xiàn)去掉動態(tài)網(wǎng)頁的參數(shù),但在實際的網(wǎng)頁目錄中并沒有必要實現(xiàn)存在重寫的頁面
    2015-12-12
  • 使用PHP如何實現(xiàn)高效安全的ftp服務(wù)器(二)

    使用PHP如何實現(xiàn)高效安全的ftp服務(wù)器(二)

    這篇文章主要介紹了使用PHP如何實現(xiàn)高效安全的ftp服務(wù)器(二)的相關(guān)資料,需要的朋友可以參考下
    2015-12-12
  • php獲得剛插入數(shù)據(jù)的id 的幾種方法總結(jié)

    php獲得剛插入數(shù)據(jù)的id 的幾種方法總結(jié)

    今天小編就為大家分享一篇php獲得剛插入數(shù)據(jù)的id 的幾種方法總結(jié),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • ThinkPHP2.0讀取MSSQL提示Incorrect syntax near the keyword ''AS''的解決方法

    ThinkPHP2.0讀取MSSQL提示Incorrect syntax near the keyword ''AS''

    這篇文章主要介紹了ThinkPHP2.0讀取MSSQL提示Incorrect syntax near the keyword 'AS'的解決方法,需要的朋友可以參考下
    2014-06-06
  • PHP安裝threads多線程擴展基礎(chǔ)教程

    PHP安裝threads多線程擴展基礎(chǔ)教程

    php5.3或以上,且為線程安全版本。apache和php使用的編譯器必須一致,通過phpinfo()查看Thread Safety為enabled則為線程安全版,通過phpinfo()查看Compiler項可以知道使用的編譯器,本文給大家介紹PHP安裝threads多線程擴展基礎(chǔ)教程,需要的朋友參考下
    2015-11-11

最新評論

阿图什市| 庆云县| 天津市| 宜兰县| 贺兰县| 高平市| 新建县| 涪陵区| 石泉县| 揭阳市| 江山市| 舞阳县| 扶沟县| 温州市| 彰武县| 拉萨市| 临湘市| 赤峰市| 巍山| 都匀市| 长宁县| 商城县| 天镇县| 张掖市| 施秉县| 如东县| 巩留县| 博兴县| 江华| 新郑市| 榆林市| 介休市| 宁阳县| 双江| 剑阁县| 鄂托克前旗| 太仆寺旗| 武汉市| 贺兰县| 鸡东县| 德庆县|