先下載對應phpExcel 的包就行了https://github.com/PHPOffice/PHPExcel
下載完成 把那個Classes 這個文件夾里面的 文件跟文件夾拿出來就好了。
直接寫到PHPExcel 這個文件里面的。調用很簡單。引入phpExcel 這個類傳遞對應的excel 文件的路徑就好了
現在上傳到指定的目錄,然后加載上傳的excel文件讀取這里讀取是的時候不轉換數組了。注意:是Sheet可以多個讀取,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
|
header('Content-type: text/html; charset=utf-8'); //設置頁面編碼 require_once 'phpexcel.class.php'; //引入文件 require_once 'PHPExcel/IOFactory.php'; //引入文件 require_once 'PHPExcel/Reader/Excel2007.php'; //引入文件 $uploadfile = $_FILES['select_file']['tmp_name']; //獲取上傳文件 $auid = $_SESSION['auid']; $date = date('Ymd'); $rand = rand(1,9999); $_month=str_replace('-','',$date); $file_name = str_pad($auid, 4, 0, STR_PAD_LEFT).$date.str_pad($rand, 4, 0, STR_PAD_LEFT).'.xlsx'; $path_file = '../data/upload/file/'.$file_name; //上傳文件目錄指定 move_uploaded_file($uploadfile, $path_file); //文件上傳 $inputFileType = PHPExcel_IOFactory::identify($path_file); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objReader->setReadDataOnly(true);//只需要添加這個方法實現表格數據格式轉換 $objPHPExcel = $objReader->load($path_file); $sheet_read_arr = array(); $sheet_read_arr["表1"] = array("B","C"); $sheet_read_arr["表2"] = array("B","C"); $sheet_read_arr["表3"] = array("B","C"); $list_aray=array(); foreach ($sheet_read_arr as $key => $val){ $currentSheet = $objPHPExcel->getSheetByName($key); $row_num = $currentSheet->getHighestRow(); for ($i = 6; $i <= $row_num; $i++){ $cell_values = array(); foreach ($val as $cell_val){ $address = $cell_val . $i;// 單元格坐標 $cell_values[] = $currentSheet->getCell($address)->getFormattedValue(); } $list_aray[]=$cell_values; } } |
以上這篇phpexcel導入excel處理大數據(實例講解)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/sztx/p/7405807.html