一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

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

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

php-excel-reader下載地址: http://www.jb51.NET/codes/67223.html

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

我使用的excel如下圖:

php-excel-reader style="DISPLAY: block; MARGIN-LEFT: auto; MARGIN-RIGHT: auto" alt=php-excel-reader src="/d/file/itjie/phpjishu/2014-10-22/eef29f59537eae720fd1b1e295d14a10.png">php代碼如下:
復(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文件 style="DISPLAY: block; MARGIN-LEFT: auto; MARGIN-RIGHT: auto" alt=php-excel-reader讀取excel文件 src="/d/file/itjie/phpjishu/2014-10-22/b3dd1e26afdbecc7a620c351eddaf1a4.png">再來說說這個類的小問題:

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

解決:將excel_reader2.php源碼中split改為explode,詳情點(diǎn)擊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()中 &去掉,因?yàn)?a href=/itjie/phpjishu/ target=_blank class=infotextkey>php5.3中廢除了=& 符號直接用=引用

(3)亂碼問題解決:

構(gòu)造函數(shù)是function Spreadsheet_Excel_Reader($file='',$store_extended_info=true,$outputEncoding=''),它默認(rèn)的編碼是utf-8,如果不指定,可能會出現(xiàn)亂碼問題,可通過$data->setOutputEncoding('GBK');指定,還有如果你使用dump()函數(shù),dump()函數(shù)將excel內(nèi)容一html格式輸出,使用htmlentities將字符轉(zhuǎn)化為html的,它默認(rèn)使用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文件就是這么簡單

php技術(shù)php讀取EXCEL文件 php excelreader讀取excel文件,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 最近最新中文字幕在线第一页 | 国产福利免费 | 国产1区2区3区在线观看 | 激情五月深爱五月 | 国产精品亚洲二区在线 | 综合色爱 | 成人在线第一页 | 久久婷婷五色综合夜啪 | 999免费视频 | 亚洲成a人一区二区三区 | 亚拍一区| 亚洲国产激情 | 亚洲乱亚洲乱妇41p国产成人 | 香蕉人人超人人超免费看视频 | 欧美精品综合 | 另类一区二区三区 | 91国内精品久久久久免费影院 | 一级一级女人18毛片 | 国产成人激烈叫床声视频对白 | 国产精品美女久久久久 | 久久国产精品-久久精品 | 五月婷婷丁香在线 | 亚洲日本中文字幕在线2022 | 国产综合亚洲欧美日韩一区二区 | 国产精品久久久久鬼色 | 久9久9精品视频在线观看 | 秋霞伊人 | 91福利视频网站 | 青青草国产免费久久久91 | 午夜视频国产 | 在线一区二区三区 | 国产原创麻豆精品视频 | 国产高清精品91在线 | 夜夜夜夜夜夜夜猛噜噜噜噜噜噜 | 色婷婷资源网 | 人人干在线观看 | 欧美亚洲另类图片 | 国产五区| 91国内精品视频 | 亚洲小说图片区 | 91免费视频播放 |