How to insert excel table in mysql using php

Asked

Viewed 244 times

0

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

php usage currently

Thank you for your attention!

1 answer

1


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

Shown here is a preview of it:

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

First you will upload the document, using move_uploaded_file

Then use the https://github.com/PHPOffice/PhpSpreadsheet to extract document data, the formats supported by PhpSpreadsheet sane:

  • 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
  • Wildebeest
  • HTML
  • SYLK
  • CSV

To install you need to use 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

So in your document you have to have something like after uploading:

<?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 document cells use https://phpspreadsheet.readthedocs.io/en/develop/topics/accessing-cells/

For example cell phone B8:

$spreadsheet->getActiveSheet()->getCell('B8');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.