I have a problem with phpexcel and joomla. I am developing some form of filter to load excel reports, so I used the phpexcel library to do this. Right now I only have a report, it works fine, but after that I load inside joomla using the PHP page component , which allows me to put php files inside joomla and name it.
When I put them, I slightly change the form that calls php, which generates an excel report, I call php, using a link like this:
h**p:
That is, calling it from Joomla, and not directly php. If I want to call php directly, I can use this path:
h**p:
What is the problem? The problem is that when I call php that generates excel via joomla, the excel that loads is damaged and only displays characters in one cell when I open it. But if I call php directly, the report is generated perfectly. I could call php directly, the problem is that if I call it directly, I cannot use this line of code:
defined( '_JEXEC' ) or die( 'Restricted access' );
This is used to deny direct access to php from calling it directly, because it does not work, because it is security.
Where is the problem? This is the php code that generates the report (ommiting code where the rows and cells are generated):
<?php
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$objPHPExcel->getActiveSheet()->setTitle('Reporte de Importaciones');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="repPrueba.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;