Posts tagged with excel

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

"Freek publishes a super resourceful and practical newsletter. A must for anyone in the Laravel space"

Joey Kudish — Shipping with AI as a teammate

No spam. Unsubscribe anytime. You can also follow me on X.

Introducing Laravel Excel 3.1

medium.com

Patrick Brouwers is doing an awesome job creating a quality Laravel package to integrate with Excel. The newest version can import Excel files.

Laravel Excel 3.0 was released a while ago and completely redesigned the architecture behind exports. Our next target was to do the same paradigm shift for imports. Development took some time, because we wanted to get it right from the start.

Read more [medium.com]

Laravel Excel — Lessons Learned

Last week Laravel Excel v3 was released. In a post on his company blog Patrick Brouwers writes the story of why and how v3 was released.

Laravel Excel (https://github.com/Maatwebsite/Laravel-Excel) turned 4 years last November and has reached almost 6 million Packagist downloads. A good time to reflect on 4,5 years of open source development.

https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551

Read more

Excel exports

Evan Miller makes the case for offering xls-exports instead of csv-exports.

Most people of your website’s users are also Excel users. When they export their data as CSV, they’ll probably just bring it into Excel first to have a look around. You should probably offer an explicit XLS export, and take it seriously.
http://www.evanmiller.org/please-offer-an-excel-export-option.html

An xls-file is capable of things that 'll never be possible in csv:

  • freezing the header row
  • formatting important cells
  • multiple sheets in one file
  • specify numer formatting
  • formulas
In the projects I've been working on I've been doing this for a couple of months. A nice Laravel package you can use is Laravel Excel.

This is how you export all values from a given repository that returns Eloquent models:


Excel::create($pathToFile, function($excel) {

    $excel->sheet('The sheet name', function($sheet) {
        $sheet->freezeFirstRow();

        $sheet->cells('A1:Z1', function($cells) {
            $cells->setFontWeight('bold');
            $cells->setBorder('node', 'none', 'solid', 'none');
        });

        $sheet->fromModel($this->yourOwnRepository->getAll());
    });

})->export('xls');

The result is an excel-file with the header row frozen and underlined and it's values in bold.

Read more