- 相關(guān)推薦
如何使用php獲取excel文件數(shù)據(jù)
文章主要介紹了php獲取excel文件數(shù)據(jù)的方法。具有很好的參考價值。下面跟著小編一起來看下吧。
1、下載PHPExcel類,是一個文件夾,還得有一個文件PHPExcel.php,兩個在同級目錄
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require __DIR__ . './PHPExcel/IOFactory.php';
$PHPReader = new \PHPExcel_Reader_Excel2007();
//判斷文件類型
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
echo 'no Excel';
return false;
}
}
$PHPExcel = $PHPReader->load($filePath);
/**讀取excel文件中的第一個工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得最大的列號*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
/**從第1行開始輸出*/
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
/**從第A列開始輸出*/
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
/**ord()將字符轉(zhuǎn)為十進制數(shù)*/
$date[$currentRow - 1][] = $val;
}
}
return $date;
【如何使用php獲取excel文件數(shù)據(jù)】相關(guān)文章:
如何在PHP導出excel格式數(shù)據(jù)10-18
如何實現(xiàn)PHP獲取表單數(shù)據(jù)與HTML嵌入PHP腳本09-23
Access 2007中的數(shù)據(jù)如何導入Excel文件08-11
PHP如何獲取表單07-27
PHP如何使用curl實現(xiàn)數(shù)據(jù)抓取09-27
如何使用php語言實現(xiàn)文件名稱以及擴展名的獲取08-07
PHP文件是什么 如何打開PHP文件08-09
PHP獲取文件名稱的方法07-05
如何打開php文件06-12
PHP文件如何打開05-06