PhpSpreadsheet provides a PHP library of classes to read and write formats such as LibreOffice Calc, Microsoft Office and CSV. The default encoding uses UTF-8.
Ref: https://phpspreadsheet.readthedocs.io/en/latest/faq/
In Laravel 5, 6 and 7, this is available through the Composer.
composer require phpoffice/phpspreadsheet niklasravnsborg/laravel-pdf mpdf/mpdf:8.1.6 league/csv
OR
composer require phpoffice/phpspreadsheet niklasravnsborg/laravel-pdf mpdf/mpdf league/csv
Here is an example of how to read the first three columns of an xlsx file, where the first row is considered as headers.
Step 1: Import the class for LibreOffice
Or for Microsoft Excel
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
Step 2: In the function that is to retrieve the data, declare object for LibreOffice
OR for Microsoft Excel
Step 3: Load the spreadsheet data
$spreadsheet = $reader->load($path);$sheet = $spreadsheet->getActiveSheet();
No comments:
Post a Comment