Hello
I have a problem when I want to import an excel file into cakeph 3, here is the error message I get: Class ‘App \ Controller \ PHPExcel_IOFactory’ not found
here is the code for my controller:
use Cake\ORM\TableRegistry;
use App\Model\Table\Contrat;
use PHPExcel\Classes\PHPExcel;
use PHPExcel\Classes\PHPExcel\IOFactory;
require ROOT.DS.‘vendor’.DS.‘phpoffice/phpexcel/Classes/PHPExcel.php’;
require ROOT.DS.‘vendor’.DS.‘phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php’;
My function importContrat :
public function importContrat()
{
if(!empty($this->request->data))
{
$this->loadModel('Marche');
$filename = $this->request->data['lien_file']['tmp_name'];
$extension = strtolower(pathinfo($this->request->data['lien_file']['name'], PATHINFO_EXTENSION));
if(!empty($filename) && in_array($extension, array('xls')))
{
//lecture du fichier avec PHPExcel
$objPHPExcel = PHPExcel_IOFactory::load($filename);
foreach($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for($row=2; $row<=$highestRow; $row++)
{
$numContrat = $worksheet->getCellByColumnAndRow(1, $row)->getValue();
$prestataire = $worksheet->getCellByColumnAndRow(2, $row)->getValue();
$segment = $worksheet->getCellByColumnAndRow(3, $row)->getValue();
$lotissement = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
$libelle = $worksheet->getCellByColumnAndRow(5, $row)->getValue();
$valeurCible = $worksheet->getCellByColumnAndRow(6, $row)->getValue();
$date_debut = implode('-', array_reverse(explode('/', $worksheet->getCellByColumnAndRow(7, $row)->getValue())));
$date_fin = implode('-', array_reverse(explode('/', $worksheet->getCellByColumnAndRow(8, $row)->getValue())));
$valeurRestanteCalculee = $worksheet->getCellByColumnAndRow(9, $row)->getValue();
$montantCommande = $worksheet->getCellByColumnAndRow(10, $row)->getValue();
$montantReceptionne = $worksheet->getCellByColumnAndRow(11, $row)->getValue();
…
I manage to import the PHPEXCEL class without problem with APP :: import() on cakephp 2.6, but impossible on cakephp 3, I really need help thanks.