How to insert excel table in mysql using php

0

I have a table in excel with more than 300 lines and I would like to insert the data of this table in mysql in phpmyadmin

Currently php usage

Thank you for your attention!

    
asked by anonymous 25.03.2018 / 00:14

1 answer

1

If it is a job that will be done only once and / or is migrating from an excel to your bank, you can download MySQL Installer which has several tools in:

Here is a preview of it:

Now if the intention is to actually work .xls and .xlsx documents with PHP via upload then I recommend that you keep in mind that much of you will have to develop:

First the document will be uploaded using move_uploaded_file

Then use the link to extract the document data, the formats supported by PhpSpreadsheet are:

  • Open Document Format / OASIS (.ods)
  • Office Open XML (.xlsx) Excel 2007
  • BIFF 8 (.xls) Excel 97 and above
  • BIFF 5 (.xls) Excel 95
  • SpreadsheetML (.xml) Excel 2003
  • Gnumeric
  • HTML
  • SYLK
  • CSV

To install you need to use the composer, if you already have composer installed then via CMD or terminal navigate to the project folder and run the command:

composer require phpoffice/phpspreadsheet

Then in your document you will have to have something like after the upload:

<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\IOFactory;

... upload vai aqui ...

//Arquivo upload
$inputFileName = './upload/example1.xls';

$spreadsheet = IOFactory::load($inputFileName);

Then to access the cells of the document use link

For example, cell phone B8:

$spreadsheet->getActiveSheet()->getCell('B8');
    
25.03.2018 / 01:10