How to install PhpSpreadsheet in Laravel

Before, I am using PHPExcel library to create, parse, and manipulate excel and csv files in Laravel. However, the project was officially deprecated in 2017 and permanently archived in 2019. The authors recommended migrating to PhpSpreadsheet as an alternative.

Most of the functions of PhpSpreadsheet is similar to PHPExcel so it’s easy to transition between the 2 libraries.

Here are the steps to install PhpSpreadsheet in Laravel

run this composer command in the root of your Laravel application.
composer require phpoffice/phpspreadsheet

add these alias namespaces in your Controller. You can add other aliases of phpSpreadsheet depending on your requirements.
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

try to use the basic example given in phpSpreadsheet website.
public function test_page()
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);

Now if you would run the page, you can see the hello_world.xlsx file generated
inside your public/ folder. This means that phpSpreadsheet is now installed and
working alright in your Laravel application.