SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.28k stars 1.92k forks source link

[Bug]: Formula Error even if `pre_calculate_formulas` is false #4189

Open Seb33300 opened 2 months ago

Seb33300 commented 2 months ago

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

What version of Laravel Excel are you using?

3.1.56

What version of Laravel are you using?

11.20.0

What version of PHP are you using?

8.2.13

Describe your issue

The pre_calculate_formulas option is set to false in my config file:

return [
    'exports' => [
        // ...
        'pre_calculate_formulas' => false,
        // ...

If I understand properly, this option is intended to disable formula during exports?

But I still get the following error when exporting data from a collection:

TITLE!AI7 -> Formula Error: Unexpected operator '='

Content of cell AI7 is a string starting by == looking like this:

== example of string ==

How can the issue be reproduced?

Set the pre_calculate_formulas option to false and try to export a string starting by ==

What should be the expected behaviour?

The cell should be exported as string.

patrickbrouwers commented 2 months ago

It doesn't disable formulas, it precalculates the result. Because the string starts with = PhpSpreadsheet will automatically detect the data type as a formula and insert it as such. You'll have to mark the value as string, by customizing the default value binder: https://docs.laravel-excel.com/3.1/imports/custom-formatting-values.html#value-binder

Seb33300 commented 2 months ago

Thanks for the information.

I wish we could have a way to disable formulas globally. It feels a bit cumbersome to override the default value binder in every export that may include user text data (literally all of our exports...)

patrickbrouwers commented 2 months ago

You can configure a custom value binder in your config as mentioned in the docs: https://docs.laravel-excel.com/3.1/exports/column-formatting.html#default-value-binder