四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

php開發中肯定會遇到將excel文件內容導入到數據庫的需要,php-excel-reader是一個讀取excel的類,可以很輕松的使用它讀取excel文件非常方便。

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

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

我使用的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代碼如下:
復制代碼 代碼如下:
<?php
/*by www.phpddt.com*/
header("Content-Type:text/html;charset=utf-8");
require_once 'excel_reader2.php';
//創建對象
$data = new Spreadsheet_Excel_Reader();
//設置文本輸出編碼
$data->setOutputEncoding('UTF-8');
//讀取Excel文件
$data->read("example.xls");
//$data->sheets[0]['numRows']為Excel行數
for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
//$data->sheets[0]['numCols']為Excel列數
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
//顯示每個單元格內容
echo $data->sheets[0]['cells'][$i][$j].' ';
}
echo '<br>';
}
?>

讀取結果截圖如下

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)出現Deprecated: Function split() is deprecated in 。。。錯誤

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

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

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

(3)亂碼問題解決:

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

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

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

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

2.將excel數據存入數組中,使用$data->sheets,打印下如下:
復制代碼 代碼如下:
Array
(
[0] => Array
(
[maxrow] => 0
[maxcol] => 0
[numRows] => 5
[numCols] => 4
[cells] => Array
(
[1] => Array
(
[1] => 編號
[2] => 姓名
[3] => 年齡
[4] => 學號
)
[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
)
)

這樣你應該知道怎么取excel中的數據了,好了,使用php-excel-reader讀取excel文件就是這么簡單

php技術php讀取EXCEL文件 php excelreader讀取excel文件,轉載需保留來源!

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

主站蜘蛛池模板: 鬼迷心窍 电影| 女人的战争剧情介绍| 四川影视文艺频道| 陕西单招真题电子版| 新红楼梦电影| 电影《林海雪原》| 赖小子| a级性片| 算死草粤语| 风间由美的作品| 杨东波| 多田有花与老丈人电影叫什么名字| 徐贤电视剧| 外出韩版| 快播电影网| 红髅| 灰姑娘电影| 误杀1演员表| 热点新闻素材| 巴黎最后的探戈| 简单的公告范文| 卡塔丽娜| 电影《影》| 1988版14集电视剧平凡的世界 | 第一财经今日股市直播间在线直播| 1988田螺姑娘| 木偶人| deauxma| 妈妈的爱情房客 电影| 伦理 在线| 王艺嘉| 少年派2高清免费观看电视剧预告 成全免费观看高清电影大侦探 | 富贵黄金屋国语| 电影白上之黑| 挠60分钟美女腋窝视频| 嗯~啊~快点死我男男视频 | 雪山飞狐之塞北宝藏演员表| 荒野求生21天美国原版观看| 大乔未久电影| 张俪床戏| 狼来了ppt免费下载|