How to handle EXCEL with PHP?

Asked

Viewed 1,615 times

0

How do I manipulate excel cells with PHP?

For example: I need to take 2 cells, in separate lines 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

In case you don’t know how, I have another question: What if I save the CSV spreadsheets in the database and also manipulate with PHP? Is there a way?! Gives same example as the one above...

  • CSV format is not unique to EXCEL, it is a tabular text format and with a column separation pattern. For example the most common way is to circle the value of the column with quotes " and separate the columns with semicolon ; If you open a CSV file in the text editor you will see what I am talking about and possibly understand that your solution is to take the column in the position you want and add the value, but reading a line from a text file and not from an EXCEL format

  • Fine. I know it’s not exclusive, but I just said I’m using csv from excel. And I want to know how to manipulate COM PHP.

  • You could use a p Phpexecel, if that’s your problem. I hope it helps.

1 answer

1


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

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 helps you:

Browser other questions tagged

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