這篇文章介紹的內容是關於PHP處理excel文件數據,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
文章主要記錄如何使用PHPexcel外掛程式對excel文件進行處理的過程,僅作備忘使用,如插件下載遇到問題,可以留言,謝謝瀏覽。以下是筆記內容:
1、引入excel外掛檔案
1 | require_once ('./PhpSpreadsheet/vendor/autoload.php');
|
登入後複製
2、取得表格資料內容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader( "Xlsx" );
$spreadsheet = $reader ->load( $file_path );
$sheetNum = $spreadsheet ->getSheetCount();
$sheetData = [];
$temp = [];
for ( $i = 0; $i < $sheetNum ; $i ++){
$temp = $spreadsheet ->getSheet( $i )->toArray(null, true, true, true);
foreach ( $temp as $v ) {
if ( is_float ( $v ['A'])){
$sheetData [] = $v ;
}
}
}
|
登入後複製
輸出格式內容如下:
3.取得資料中自己覺得有用的部分:
1 2 3 4 5 6 7 8 9 10 11 | $excel_records $temp = [];
$excel_records = [];
foreach ( $sheetData as $v ){
$temp [' date '] = gmdate ( "Y-m-d" , ( $v ['A'] -25569) * 86400);
$temp ['drname'] = $v ['B']; $temp ['uid'] = $v ['C']; $temp ['imei'] = $v ['D']; $temp ['reg_date'] = $v ['E']; $excel_records [] = $temp ;
}
|
登入後複製
後續直接對資料進行處理即可。
相關推薦:
php處理陣列key值變更
#php處理表單上傳檔案的方法
以上是PHP處理excel檔案數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!