Spatie/Simple-Excel is a safe package to use in a live Laravel release. It is a lightweight package that provides a simple and intuitive API for importing and exporting Excel files. It is actively maintained by the Spatie team and has a good reputation in the Laravel community.
To export data to an Excel spreadsheet using Spatie/Simple-Excel, you can follow these steps:
- Install the package via Composer:
composer require spatie/simple-excel
- Use the
SimpleExcelWriterclass to create an Excel file and write data to it. Here's an example:
use Spatie\SimpleExcel\SimpleExcelWriter;
// Create a new Excel file
$excel = SimpleExcelWriter::create('path/to/file.xlsx');
// Add data to the file
$excel->addRow(['Name', 'Email']);
$excel->addRow(['John Doe', '[email protected]']);
$excel->addRow(['Jane Smith', '[email protected]']);
// Save the file
$excel->save();
- To import data from an Excel file, you can use the
SimpleExcelReaderclass. Here's an example:
use Spatie\SimpleExcel\SimpleExcelReader;
// Read data from an Excel file
$excel = SimpleExcelReader::open('path/to/file.xlsx');
// Iterate over each row
foreach ($excel->getRows() as $row) {
$name = $row['Name'];
$email = $row['Email'];
// Process the data as needed
// ...
}
Remember to replace 'path/to/file.xlsx' with the actual path to your Excel file.
Overall, Spatie/Simple-Excel is a reliable package for Excel import/export in Laravel. It provides a straightforward API and should meet your needs for exporting data to an Excel spreadsheet.