国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 後端開發(fā) php教程 php讀取EXCEL文件 php excelreader讀取excel文件_PHP教程

php讀取EXCEL文件 php excelreader讀取excel文件_PHP教程

Jul 21, 2016 pm 03:14 PM
excel php 開發(fā) 文件 讀取 遇到

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

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

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

我使用的excel如下圖:

php-excel-readerphp代碼如下:

復制代碼 代碼如下:

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

讀取結果截圖如下

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)亂碼問題解決:

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

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

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

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

2.將excel數(shù)據(jù)存入數(shù)組中,使用$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中的數(shù)據(jù)了,好了,使用php-excel-reader讀取excel文件就是這么簡單

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326250.htmlTechArticlephp開發(fā)中肯定會遇到將excel文件內容導入到數(shù)據(jù)庫的需要,php-excel-reader是一個讀取excel的類,可以很輕松的使用它讀取excel文件非常方便。...
本網(wǎng)站聲明
本文內容由網(wǎng)友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發(fā)現(xiàn)涉嫌抄襲或侵權的內容,請聯(lián)絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

如何在PHP中獲取當前的會話ID? 如何在PHP中獲取當前的會話ID? Jul 13, 2025 am 03:02 AM

在PHP中獲取當前會話ID的方法是使用session_id()函數(shù),但必須先調用session_start()才能成功獲取。 1.調用session_start()啟動會話;2.使用session_id()讀取會話ID,輸出類似abc123def456ghi789的字符串;3.若返回為空,檢查是否遺漏session_start()、用戶是否首次訪問或會話是否被銷毀;4.會話ID可用於日誌記錄、安全驗證和跨請求通信,但需注意安全性。確保正確開啟會話後即可順利獲取ID。

php從字符串獲取子字符串 php從字符串獲取子字符串 Jul 13, 2025 am 02:59 AM

要從PHP字符串中提取子字符串,可使用substr()函數(shù),其語法為substr(string$string,int$start,?int$length=null),若未指定長度則截取至末尾;處理多字節(jié)字符如中文時應使用mb_substr()函數(shù)以避免亂碼;若需根據(jù)特定分隔符截取字符串,可使用explode()或結合strpos()與substr()實現(xiàn),例如提取文件名擴展名或域名。

您如何執(zhí)行PHP代碼的單元測試? 您如何執(zhí)行PHP代碼的單元測試? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

如何將字符串分為PHP中的數(shù)組 如何將字符串分為PHP中的數(shù)組 Jul 13, 2025 am 02:59 AM

在PHP中,最常用的方法是使用explode()函數(shù)將字符串拆分為數(shù)組。該函數(shù)通過指定的分隔符將字符串分割成多個部分並返回數(shù)組,語法為explode(separator,string,limit),其中separator為分隔符,string為原字符串,limit為可選參數(shù)控制最大分割數(shù)量。例如$str="apple,banana,orange";$arr=explode(",",$str);結果為["apple","bana

JavaScript數(shù)據(jù)類型:原始與參考 JavaScript數(shù)據(jù)類型:原始與參考 Jul 13, 2025 am 02:43 AM

JavaScript的數(shù)據(jù)類型分為原始類型和引用類型。原始類型包括string、number、boolean、null、undefined和symbol,其值不可變且賦值時復制副本,因此互不影響;引用類型如對象、數(shù)組和函數(shù)存儲的是內存地址,指向同一對象的變量會相互影響。判斷類型可用typeof和instanceof,但需注意typeofnull的歷史問題。理解這兩類差異有助於編寫更穩(wěn)定可靠的代碼。

在C中使用std :: Chrono 在C中使用std :: Chrono Jul 15, 2025 am 01:30 AM

std::chrono在C 中用於處理時間,包括獲取當前時間、測量執(zhí)行時間、操作時間點與持續(xù)時間及格式化解析時間。 1.獲取當前時間使用std::chrono::system_clock::now(),可轉換為可讀字符串但係統(tǒng)時鐘可能不單調;2.測量執(zhí)行時間應使用std::chrono::steady_clock以確保單調性,並通過duration_cast轉換為毫秒、秒等單位;3.時間點(time_point)和持續(xù)時間(duration)可相互操作,但需注意單位兼容性和時鐘紀元(epoch)

如何將會話變量傳遞給PHP中的另一頁? 如何將會話變量傳遞給PHP中的另一頁? Jul 13, 2025 am 02:39 AM

在PHP中,要將一個會話變量傳到另一個頁面,關鍵在於正確開啟會話並使用相同的$_SESSION鍵名。 1.每個頁面使用session變量前必須調用session_start(),且放在腳本最前面;2.在第一個頁面設置session變量如$_SESSION['username']='JohnDoe';3.在另一頁面同樣調用session_start()後通過相同鍵名訪問變量;4.確保每個頁面都調用session_start()、避免提前輸出內容、檢查服務器上session存儲路徑可寫;5.使用ses

PHP如何處理環(huán)境變量? PHP如何處理環(huán)境變量? Jul 14, 2025 am 03:01 AM

toAccessenvironmentVariablesInphp,useGetenv()或$ _envsuperglobal.1.getEnv('var_name')retievesSpecificvariable.2。 $ _ en v ['var_name'] accessesvariablesifvariables_orderInphp.iniincludes“ e” .setVariablesViaCliWithvar = vualitephpscript.php,inapach

See all articles