Symfony 5 PhpSpreadsheet (Creating Excel File)

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.

Installation

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;

Use the 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.

🔗 Click this link for more documentation about the PHPSpreadsheet library.

— — —

Testing Benford’s Law on Symfony 5, Php Framework

Formats Supported by the API Platform

How Computer Works and What is Binary Number System?

JWT Authentication and Refresh Token to API Platform

Symfony 5 Birthday Reminder Command

Symfony user checker(check for login of users with status = active) Easy way

Symfony search engine with elasticsearch

Symfony 5 Contact Form with Mailer and Mime component(MailerInterface)

Symfony 5 Confirmation email without FosUserBundle

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store