Excel to PHP array, possible and how?

后端 未结 5 1442
滥情空心
滥情空心 2020-12-28 16:24

I have a big excel file that looks like this:

\"enter

I would like to put each

相关标签:
5条回答
  • 2020-12-28 16:53

    May be my answer is too simple (for one time work only), but I use the CONCATENATE "Function" in excell. The last cell on each row will have concatenation function, like this:

    =CONCATENATE("['";A2;"'=>['data1' => '";B2;"', 'data2' => '";C2;"'],")
    

    where:

    column "A" is ID of something;
    column "B" is first characteristic;
    column "C" is second characteristic;
    etc.
    

    Then just copy and paste function results to Your script or config file, and do not forget the first and the last bracket.

    0 讨论(0)
  • 2020-12-28 16:58

    I recommended to use PHPEXCEL library

    https://github.com/PHPOffice/PHPExcel

    you can see an example

    Update: Now the alternative to this library is phpspreadsheet

    0 讨论(0)
  • 2020-12-28 17:07

    This works for me:

    $content = file_get_contents($your_file_path); 
    $lines = array_map("rtrim", explode("\n", $content));
    
    0 讨论(0)
  • 2020-12-28 17:11

    Save the spreadsheet as a CSV, then use PHP's built-in CSV functions. See the sample code here:

    http://php.net/manual/en/function.fgetcsv.php

    0 讨论(0)
  • 2020-12-28 17:15

    Since the PHPExcel library deprecated they've released "PhpSpreadsheet"

    This will help PhpSpreadsheet

    0 讨论(0)
提交回复
热议问题