In this article, we will see how to create excel file in Symfony 5 with PhpSpreadsheet library. We will try to the simplest way to write a spreadsheet.
PhpSpreadsheet is a library written in pure PHP. It is not only support excel file for reading and writing of data, but also read and write html file data and CSV file data.
Use composer to install PhpSpreadsheet into your project:
composer require phpoffice/phpspreadsheet
Let’s get data then accessing cells in a Spreadsheet and generating file should be pretty straightforward.
Create a controller as below;
path() Twig function to link to export.
templates/home/index.html.twig as below;
Entity/User.php as below;
Start symfony server then click export and check the public folder. Our file has been created.
— — —