I have used the phpspredsheet to generate the Excel file. but all works perfect but i want to browser donwload so i have set following code but the file generate the encode with buggy characters.
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;
}
I got the Solution for this Problem.well,
Don’t Need any third party lib for export the excel. same code as i mention above used but you can use the Ob_clean() method before export the code works fine.