Where to put phpexcel lib and how use it in cakephp 3 x

composer.json
"require": { "box/spout" : "dev-master" }

composer update

Controller:

use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;

    public function xlsxSpout($id = null) {
             $user = $this->Users->get($id);
             $fileName = 'spreadsheet.xlsx';
     
             $writer = WriterFactory::create(Type::XLSX); // for XLSX files
             //$writer = WriterFactory::create(Type::CSV); // for CSV files
             
             //$writer->openToFile($fullFilePath); // write data to a file or to a PHP stream
             $writer->openToBrowser($fileName); // stream data directly to the browser
             
             $writer->addRow(['ID', 'Name', 'Email']); // header
             $writer->addRow([$user->id, $user->name, $user->email]); // add a row at a time
             //$writer->addRows($rows); // add multiple rows at a time
             $writer->close();
             
             //$this->RequestHandler->respondAs('xlsx');
             $this->autoRender = false;
        }
1 Like