Problem with formulas when exporting to Excel 2007

Hi to all,
I use Dolibarr 21 and wanted to create an Excel spreadsheet containing formulas.
I created cells whose contents begin with = (e.g., ‘=C2+C3’), but:

  • defining the column as “Text,” a ’ is inserted at the beginning, so they are viewed as strings.
  • defining the column as “Formula,” the ’ isn’t added, but they are still interpreted as strings.

How should I behave?

Hi @mgribaudo

Where are you trying this one? In Dolibarr Import/Export?

Thanks
Saikat Koley

Hi Saikat,
No, I’m writing my own export.
But I learned the export logic by browsing the Dolibarr Import/Export functions.

Hi @mgribaudo

You are doing something like this?

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

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$sheet->setCellValue(‘C2’, 10);
$sheet->setCellValue(‘C3’, 20);

$sheet->setCellValue(‘C4’, ‘=C2+C3’);

$writer = new Xlsx($spreadsheet);
$writer->save(‘myexport.xlsx’);

Best regards
Saikat Koley

no I’m using the Dolibarr ExportExcel2007 class, but maybe your idea is less “standard” but more “elastic” :slight_smile:

1 Like