For those that want to directly integrate PHPExcel into Cakephp (2.x), this is what I did, where I put it in the App/Vendor folder.
- Goto https://github.com/PHPOffice/PHPExcel and download the whole zip file. The main core folder is 'Classes'. This is what we will be using.
- Place the folder 'Classes' into your Cakephp folder 'APP/Vendor/PHPExcel'.
- Import it into your controller with this line at the top :
App::import('Vendor', 'PHPExcel', array('file' => 'PHPExcel/Classes/PHPExcel.php'));
. Note the location of the 'PHPExcel.php' file, and make sure it is there in your Cakephp folder
- You can now access the object with this line :
$objPHPExcel = new PHPExcel();
- There is a lot of example in the PHPExcel zip file that you downloaded in the first step (also found here)
.
Full example in my controller (only the function)
public function testxls() {
$folderToSaveXls = '/var/www/html';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("PHPExcel Test Document")
->setSubject("PHPExcel Test Document")
->setDescription("Test document for PHPExcel, generated using PHP classes.")
->setKeywords("office PHPExcel php")
->setCategory("Test result file");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save( $folderToSaveXls . '/test.xls' );
}
.
Hope it helps.