Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formulas not calculated when exporting as csv

I have this Excel file (.xlsx):

+---+-------+
|   |   A   |
+---+-------+
| 1 | 1     |
| 2 | =A1+1 |
| 3 | =2*3  |
+---+-------+

In Laravel I have configured this code to display the contents

return Excel::load(base_path() . '/test.xlsx')->string('csv');

which returns the text of the cells: "1","=A1+1","=3*2"

What I want is the calculated values, but with the same formatting: "1","2","6"

The code

return Excel::load(base_path() . '/test.xlsx')->get();

returns the correct calculated data, but in the wrong format.

like image 925
Daniel Avatar asked Feb 17 '26 15:02

Daniel


1 Answers

There's an option precisely for that purpose. You probably have a config file at config/excel.php (if not just do php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" ). Take a look at the export array, which holds the following option:

    /*
    |--------------------------------------------------------------------------
    | Pre-calculate formulas during export
    |--------------------------------------------------------------------------
    */
    'calculate'                   => false,

Set it to true and there you have it.

like image 153
alepeino Avatar answered Feb 19 '26 05:02

alepeino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!