Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

opheliadesign's avatar

Export a PDF document under PHP 7.1

Hi everyone,

I have been using maatwebsite/excel to generate PDFs from data in our database. It worked great until I upgraded to PHP 7.1, now I receive the following error: ErrorException: A non-numeric value encountered in /home/forge/cvahimt.org/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php:835

It is my understanding that this is an issue with phpoffice/phpexcel.

Can anyone suggest an alternative to maatwebsite/excel with good documentation?

Here is my code to give you an idea of my current needs. Data is fetched by a helper class, should not be relevant. (Sorry if the syntax highlighting isn't working, not sure why):

$entriesObj = new personnelSpreadsheetEntry($users);
        \Excel::create('CVAHIMT-personnel-export-' . date("m-d-Y"),
            function ($excel) use ($entriesObj) {
                $excel->sheet('Personnel Listing', function ($sheet) use ($entriesObj) {
                    $sheet->setOrientation('landscape');
                    $sheet->fromArray($entriesObj->generateContactSheet());
                    $sheet->row(1, function ($row) {
                        $row->setFontWeight('bold');
                        $row->setBackground('#f2e296');
                    });
                    $sheet->setAutoFilter();
                    $sheet->setFreeze('C2');
                });
                $excel->sheet('Emergency Contacts', function($sheet) use ($entriesObj) {
                    $sheet->setOrientation('landscape');
                    $sheet->fromArray($entriesObj->generateEmergencyContacts());
                    $sheet->row(1, function ($row) {
                        $row->setFontWeight('bold');
                        $row->setBackground('#f2e296');
                    });
                    $sheet->setAutoFilter();
                    $sheet->setFreeze('C2');
                });
                $excel->getDefaultStyle()
                    ->getAlignment()
                    ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $excel->setActiveSheetIndex(0);
            })->export("xls");
0 likes
2 replies
Robstar's avatar

It looks like the bug wasn't with maatwebsite\excel, it was actually with the underlying package it uses i.e. PHPOffice/PHPExcel, which has apparently been fixed. This fix hasn't been applied to the package yet according to https://github.com/Maatwebsite/Laravel-Excel/issues/1041

Have you tried using https://github.com/PHPOffice/PHPExcel directly? There is some documentation at https://github.com/PHPOffice/PHPExcel/tree/develop/Documentation/markdown/Overview

1 like
opheliadesign's avatar

@Robstar thanks for the tip. I have multiple servers/projects utilizing maatwebsite/excel and his documentation is a lot easier to follow than PHPExcel.

I'm in a time crunch for a client complaining about this issue, I do not want to downgrade PHP versions because I hope to utilize PHP 7 for a revamp of their site.

I also found maatwebsite/laravel-excel-light, https://github.com/Maatwebsite/Laravel-Excel-Light. I may try that tomorrow.

If you have any experience with PHPExcel, would you mind tossing me a bone and showing me how to execute the code in my question using its direct syntax? :) I wish they had more concise documentation.

Thanks!

Please or to participate in this conversation.