This article introduces the content of PHP processing Excel file data, has a certain reference value, now share to everyone, the need for friends can refer to
The article mainly records how to use the Phpexcel plug-in Excel file processing process, only for the use of memo, such as plugin download encountered problems, can leave a message, thank you for browsing. Here's what the note says:
1. Introduction of Excel Plugin file
Require_once ('./phpspreadsheet/vendor/autoload.php ');
2. Get Excel table Data content
Create a file read class object $reader = \phpoffice\phpspreadsheet\iofactory::createreader ("Xlsx"); /** Advise The reader, the we only want to load cell data **///is set to read-only mode $reader->setreaddataonly (true);/** Load $inputFileName to a Spreadsheet Object **///Load file path, path is absolute path $spreadsheet = $reader->load ($file _path);// Gets the number of sheet$sheetnum in the Excel table = $spreadsheet->getsheetcount (), $sheetData = []; $temp = [];//only gets active sheet//$temp = $ Spreadsheet->getsheetactive ()->toarray (null, True, true, true);//Iterate through each sheet to get the contents of the data inside 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;}} }
The output format reads as follows:
Var_dump ($sheetData);/* ' A ' = = float 41746 ' B ' = = String ' Jade Snow Reunions ' (length=12) ' C ' = = Float 236979210< c3/> ' D ' = = String ' 353343073072008 ' (length=15) ' E ' = = float 41740 ' F ' = null*/
3. Get the parts of your data that you feel are useful:
Gets the data record in the Excel table $excel_records$temp = []; $excel _records = [];foreach ($sheetData as $v) { //strtotime (gmdate (" Y-m-d ", ($sheetData [$i] [' F '] -25569) * 86400) //Convert the time string in the table to the time format $temp [' date '] = Gmdate (" y-m-d ", ($v [' A ']- 25569) * 86400);//2018 year acquired for 2014, unknown cause $temp [' drname '] = $v [' B ']; $temp [' uid '] = $v [' C ']; $temp [' imei '] = $v [' D ']; $temp [' reg_date '] = $v [' E ']; $excel _records[] = $temp;}
Subsequent processing of the data directly.