How to use phpspreadsheet in dolibarr

I saw online example that we can easily export sql to excel file.

require_once ‘vendor/autoload.php’;
require_once ‘config.php’;

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

But in dolibarr, have no using composer, so there have no vendor folder.

I try to clone from \core\modules\export\export_excel2007.modules.php
with below code, but it is not working
require_once DOL_DOCUMENT_ROOT.’/core/modules/export/modules_export.php’;
require_once DOL_DOCUMENT_ROOT.’/core/lib/date.lib.php’;

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

Any suggestion how to get Spreadsheet namespace?
Thanks.

Create custom module, install composer for this module and then execute “composer require PhpOffice\PhpSpreadsheet”.

I have implemented it in few custom modules for a clients of mine, to import .xlsx file data as customer orders.

2 Likes

I have a similar problem:
i ran the command and installed the product via composer, i created a new module but the commands:

require 'vendor / autoload.php';
use PhpOffice \ PhpSpreadsheet \ Spreadsheet;
use PhpOffice \ PhpSpreadsheet \ Writer \ Xlsx;

they don’t let me run the module with the error:
Parse error: syntax error, unexpected ‘use’ (T_USE) in C: \ …\custom \ …

I have no experience with namespaces, how can I solve?