Cannot assign null to property 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.

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:

<?= Config("EXPORT_EXCEL_FORMAT") ?>

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.

Hi:

If I modify in the ExportExcel.php line 37 from:

Líne 37: $this->Format = Config("EXPORT_EXCEL_FORMAT");

to

Líne 37: $this->Format = “Excel5”;

it works. So, Config("EXPORT_EXCEL_FORMAT"); is not working for some reason.

After changing configuration (including after enabling extension), you should Clearing Symfony Cache.

Yes, I’ve cleaned the cache with every test. The error persists. The only way of make it works is changin the value in ExportExcel.php

Then I'm sure why it happened to your site. I cannot reproduce, the listener sets the format correctly. You may delete all files in your project folder and generate all files again to make sure everything is updated, or you may enable Debug and check the log file, see if there was any error preventing the listener from setting the "EXPORT_EXCEL_FORMAT".

Deleted all files in the project. Debug enabled. No entries for EXPORT_EXCEL_FORMAT in the log. The only excel reference is:

[2026-02-06T19:29:16.914606+00:00] deprecation.INFO: User Deprecated: Class "Doctrine\ORM\Proxy\Autoloader" is deprecated. Use native lazy objects instead. (Autoloader.php:74 called by DoctrineBundle.php:136, https://github.com/doctrine/orm/pull/12005, package doctrine/orm)
{"exception":"[object] (ErrorException(code: 0): User Deprecated: Class \"Doctrine\\ORM\\Proxy\\Autoloader\" is deprecated. Use native lazy objects instead. (Autoloader.php:74 called by DoctrineBundle.php:136, https://github.com/doctrine/orm/pull/12005, package doctrine/orm) at C:/laragon/www/partes26/vendor/doctrine/deprecations/src/Deprecation.php:208)"}

[2026-02-06T19:29:16.984268+00:00] request.INFO: Matched route "api.export".
{"route":"api.export","route_parameters":{"_route":"api.export","table":"partes_jdo","key":null,"_controller":"PHPMaker2026\\Semicom2026\\ApiController::export","param":"excel"},"request_uri":"http://partes26.test/api/export/excel/partes_jdo","method":"GET"}

Those are irrelevant. Don't know how you deleted cache before, but you better delete var\cache\dev and/or var\cache\prod (make sure you delete correct cache for your dev/prod environment) manually and try again. If you have already uploaded to your production server, make sure you delete cache on the server, not just on your PC.