PHPExcel 1.8.0 and CakePHP 2.7.5 cannot list MySQL data.

Asked 5 months ago, Updated 5 months ago, 16 views

Download from --- > (1.8.0) As of November 23, 2015
(*As of May 2021, you can download it from

■ Unzip the downloaded file and rename the Classes folder to phpexcel.
Then, place the phpexcel folder under app/Vendor/

■Preparation and placement of template files
Create a phpexcel folder under app/tmp/
Place empty [template.xlsx] in 2007 format.

■ Controller Settings

public function excel(){
    $data = $this->User->findById(15);


App::import('Vendor','PHPExcel_Writer_IWriter', array('file'=>'phpexcel/PHPExcel/Writer/IWriter.php'));
App::import('Vendor','PHPExcel_Writer_Abstract', array('file'=>'phpexcel/PHPExcel/Writer/Abstract.php'));
App::import('Vendor','PHPExcel_Writer_Excel2007', array('file'=>'phpexcel/PHPExcel/Writer/Excel2007.php'));
App::import('Vendor','PHPExcel_Reader_Excel2007', array('file'=>'phpexcel/PHPExcel/Reader/Excel2007.php'));

$objReader=PHPExcel_IOFactory::createReader("Excel 2007");



$sheet->fromArray($data, null, 'A1');

$filename = 'output.xlsx';
$filename =mb_convert_encoding($filename, 'sjis', 'utf-8');

header('Content-Disposition: attachment; filename="'.$filename.'";
$objWriter=new PHPExcel_Writer_Excel 2007 ($PHPExcel);

This way, only one line of user record information with ID number 15 is
Output as an Excel file.

I would like to list all MySQL data, so I will use the controller.


This results in an invalid extension file and error.

If <php debug($data);?> on the View side, the array is properly listed.

$sheet->fromArray($data,null,'A1'); how to write
I don't think so.

Could you please tell me who you know?
Thank you for your cooperation.


2022-09-30 14:17

1 Answers

This blog:PHPExcel is convenient to use the fromArray method for writing.
Especially the foreach part.

foreach($data as$value){

2022-09-30 14:17

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.