PHP processing Excel file data

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.