Cannot assign null to property PHPMaker2026\Semicom2026\ExportExcel::$Format

Hi:

when I export to excel. No problem exporting to word, csv, etc… but when I try to export to excel I get the error:

[TypeError] Cannot assign null to property PHPMaker2026\Semicom2026\ExportExcel::$Format of type string in C:\laragon\www\partes26\src\ExportExcel.php:37

  1. After enabling the extension, you need to re-generate userfn.php or the format is not set.
  2. Also make sure you have set the format setting (under Advanced setting of the PhpSpreadsheet extension) to Excel5 or Excel2007, do not leave it empty.

Thanks for the answer.

I’ve re-generated all the files after enabling the extension several times

The format setting is set, I’ve tested Excel5 and Excel2007, same result.

I’ve tested to export in serveral tables, the same error

Tested on my local computer and in the production server to check if there was some different configuration

In userfn.php, you should find code like:

// PhpSpreadsheet
AddListener(ConfigurationEvent::class, function (ConfigurationEvent $event) {
    $event->import([
        "USE_PHPEXCEL" => true,
        "EXPORT_EXCEL_FORMAT" => "Excel5", // or "Excel2007"
    ]);
});

You can also test the config by the following in your page:

<?= Config("EXPORT_EXCEL_FORMAT") ?>

You should see your setting set in the listener above, if you see null, you might have some other code set it to null. You better double check your server events. Note that in v2026, "EXPORT_EXCEL_FORMAT" is only set by the event listener in userfn.php. If you use any third party extension, you better remove it first.

Hi arbei:

Thanks for the hints.

I have the code as it in userfn.php ("EXPORT_EXCEL_FORMAT" => "Excel5")

I’ve checked if I had any other code that set “EXPORT_EXCEL_FORMAT” to null, but I don’t

I’ve searched all my code for EXPORT_EXCEL_FORMAT and it’s just in two points (I think it’s ok)

C:\laragon\www\partes26\src\ExportExcel.php (1 coincidence)
Líne 37: $this->Format = Config("EXPORT_EXCEL_FORMAT");
C:\laragon\www\partes26\src\userfn.php (1 coincidence)
Líne 655: "EXPORT_EXCEL_FORMAT" => "Excel5",

I’ve tested your code with:

and I get: DEBUG - Format Excel:

I’ve tried too to show the values of “USE_PHPEXCEL” and “PDF_BACKEND” with the same result. So it seems the problem is in some point the value is changed.