2

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.

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-

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.

The Coder
  • 618
  • 3
  • 10
  • 22
  • What's approximate file structure, extension, size? Add more details please. And show what you have tried. – arogachev Feb 07 '15 at 05:35

2 Answers2

8

Install phpoffice/phpexcel extension with composer :

composer require phpoffice/phpexcel

In your view :

$objPHPExcel = \PHPExcel_IOFactory::load('./test.xlsx');
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
print_r($sheetData);
Christian Lescuyer
  • 18,893
  • 5
  • 49
  • 45
0

As per the instruction given by Christian Lescuyer, I installed the composer dependency. but I had to edit a dependency file.

in file vendor\phpoffice\phpexcel\Classes\PHPExcel\Shared\OLE.php, line 288 I had to remove "continue;" and add "break;" in its place.

Bhaumik Belani
  • 652
  • 1
  • 8
  • 19