'Excel / PHPSpreadSheet : LOAD and SAVE WITH Charts, unexpected argument

I'm trying to load my excel file through PHPSpreadSheet library including the charts. At the reader step, everything is working fine and I could without difficulty use the LOAD_WITH_CHARTS flag as the documentation.

But when I'm trying to save my file (I have to save it with the charts as well), fatal error.

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Calculation\Exception: Formula Error: Unexpected ,

PHPSpreadSheet doesn't seem to accept my second argument after the , (the flag). Here my PHP code directly took from the documentation :

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;

$reader = IOFactory::createReaderForFile("books.xlsx");
$spreadsheet = $reader->load("books.xlsx", $reader::LOAD_WITH_CHARTS);

$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'New Value');

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('test.xlsx', $writer::SAVE_WITH_CHARTS);

I tried this :

$writer->save('test.xlsx');

It is working fine without the SAVE FLAGS, it seems to be the problem but I really need this flag.

Here the doc part about flags on PHPSPreadSheet https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-and-writing-to-file/#readerwriter-flags

Any idea ? Thanks for reading, have a nice end of week

EDIT : By adding

$writer->setPreCalculateFormulas(false);

It seems to be working, but by adding this parameter the file loose a lot of settings like the Charts color by example



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source