0
votes

I have a problem with phpspreadsheet in codeigniter, this is the simple code:

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
public function modificaAzioneFormativa(){

require 'test/vendor/autoload.php';
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue("A1", "Ciao mondo!");
$writer = new Xlsx($spreadsheet);
$writer->save('prova.xlsx');

i receive this error

Fatal error: Trait 'PhpOffice\PhpSpreadsheet\Spreadsheet' not found in /Applications/MAMP/htdocs/cubo/application/controllers/Users.php on line 1400 A PHP Error was encountered

Severity: Error

Message: Trait 'PhpOffice\PhpSpreadsheet\Spreadsheet' not found

Filename: controllers/Users.php

Line Number: 1400

Backtrace:

Anyone can help me ?

1

1 Answers

1
votes

The 'use' keyword has a bunch of different meanings in PHP. It can be be used in namespaces, traits, or binding variables to anonymous functions.

In this case, your code is trying to use a trait. It looks to me like maybe those are not supposed to be traits, but namespace declarations instead. If that's the case, move them out of the class definition and to the top of your file, before executing any other code.