# Import class PHPEXCEL

**URL:** <https://discourse.cakephp.org/t/import-class-phpexcel/7149>\
**Category:** Need Help\
**Created:** [January 22, 2020, 2:03pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149 "2020-01-22T14:03:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![schloter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@schloter](https://discourse.cakephp.org/u/schloter)\
**Post date:** [January 22, 2020, 2:03pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/1 "2020-01-22T14:03:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 22, 2020, 3:39pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/2 "2020-01-22T15:39:38Z")

</div>

What’s the full namespaced name of the class? You `use PHPExcel\Classes\PHPExcel\IOFactory` but then reference `PHPExcel_IOFactory`. Those are different things.

---

<div class="post-metadata">

**Author:** ![schloter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@schloter](https://discourse.cakephp.org/u/schloter)\
**Post date:** [January 23, 2020, 1:03pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/3 "2020-01-23T13:03:16Z")

</div>

because in the IOFactory.php file, the class is named:

class PHPExcel\_IOFactory  
{  
…  
}

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 23, 2020, 2:31pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/4 "2020-01-23T14:31:57Z")

</div>

And what namespace is it in?

---

<div class="post-metadata">

**Author:** ![schloter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@schloter](https://discourse.cakephp.org/u/schloter)\
**Post date:** [January 24, 2020, 1:32pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/5 "2020-01-24T13:32:55Z")

</div>

thanks, i found the solution :  
require\_once(APP. ‘Vendor’.DS.‘PHPExcel’.DS.‘IOFactory.php’);  
in my function importContrat:  
$objPHPExcel = \PHPExcel\_IOFactory::load($filename);

---

<div class="post-metadata">

**Author:** ![deanoj](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@deanoj](https://discourse.cakephp.org/u/deanoj)\
**Post date:** [January 28, 2020, 3:21pm UTC](https://discourse.cakephp.org/t/import-class-phpexcel/7149/6 "2020-01-28T15:21:15Z")

</div>

If this is the library I think it is - it would be a lot easier to add this as a composer dependency:

`"phpoffice/phpexcel": "1.8.1",`

I just ignore the warnings about it been abandoned - its does the job i need it to do…
