How to handle EXCEL with PHP?

0

How do I manipulate cells from excel with PHP?

For example: I need to get 2 cells in different rows Cell 1: AB2 Cell 2: BC4

And multiply them AB2 * BC4 =?

And print this value on the screen. All this in PHP, but how?

File type: CSV

If you do not know how, I have another question: What if I save the CSV spreadsheets in the database and also manipulate with PHP? Has as?! Give the same example as the one above ...

    
asked by anonymous 29.06.2017 / 13:19

1 answer

1

When I need to use .csv in php I use the csv.thephpleague.com library. You can install via Composer . Contains well-taught examples that can help you.

In this way you can work cell by cell and enter into a table:

<?php
    use League\Csv\Reader;
    require '../vendor/autoload.php';

    $inputCsv = Reader::createFromPath('caminho/arquivo.csv');
    $inputCsv->setDelimiter(';');

    //captura o cabeçalho do arquivo
    $headers = $inputCsv->fetchOne(0);

    //Retorna no máximo 25 linhas, começando pela linha 801
    $res = $inputCsv->setOffset(800)->setLimit(25)->fetch();
?>

In this link there is a practical example, I hope it will help you: / p>     

29.06.2017 / 15:03