How to read excel file and display data in Yii 2?

[font="Arial"][size="2"] Hi, I have tried to use PHPExcel library to read the excel file and display data from the file. But it was not working for me. I have also tried using yii2-phpexcel extension also other some ways but nothing worked for me. I hope I would get help from the expert personnel.

[/size][/font][font="Arial"][size="2"]I have used PHPExcel in CakePHP to read data from excel but I have no idea how to make code workable in Yii 2. How can I load PHPExcel in Yii2? I am using XLSX. In CakePHP, I can use-

[/size]


App::import('Vendor', 'Excel/reader'); 

$data = new Spreadsheet_Excel_Reader();

$data->setOutputEncoding('CP1251');

$data->read(WWW_ROOT . 'uploads/' . $_FILES["filename"]["name"]);

$cells = $data->sheets[0]['cells'];

Thanks in advance. [/font]

Using an extension sounds like a good approach, when you say "nothing worked for me", if you give details someone might be able to point you in the right direction.

Teorically there is no limit in using external library in yii2.

If you use PHPExcel just include the file and use the lib as in specified in PHPExcel docs.

I guess that you used composer phpoffice/phpexcel you can try something like




require_once(Yii::getAlias('@vendor/phpoffice/phpexce/Classes/PHPExcel.php'));

$data = new Spreadsheet_Excel_Reader();

$data->setOutputEncoding('CP1251');

$data->read(WWW_ROOT . 'uploads/' . $_FILES["filename"]["name"]);

$cells = $data->sheets[0]['cells'];



If you used the extension yii2-phpexcel I saw it lacks usage documentation.

Anyway in both case just provide more info on the problem you faced and people can try to help you