1. Go to this page and download the library: Download fersot/excel-to library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Keep only these columns
ExcelTo::file('file.xlsx')->only(['nombre', 'email'])->toArray();
// Exclude these columns
ExcelTo::file('file.xlsx')->except(['id', 'internal_code'])->toArray();
use Fersot\ExcelTo\ExcelTo;
$data = [
['producto' => 'Widget', 'precio' => 9.99, 'stock' => 100],
['producto' => 'Gadget', 'precio' => 19.99, 'stock' => 50],
];
ExcelTo::fromArray($data)->export('storage/exports/report.xlsx');
// From a Collection
ExcelTo::fromCollection($collection)->export('storage/exports/report.xlsx');
return [
'date_format' => 'd/m/Y', // Default date output format
'skip_empty' => false, // Skip empty rows by default
'header_row' => 1, // Default header row number
];