Call phpexcel from joomla

Posted by Oscar Calderon on Stack Overflow See other posts from Stack Overflow or by Oscar Calderon
Published on 2011-03-07T22:17:14Z Indexed on 2012/12/01 17:04 UTC
Read the original article Hit count: 244

Filed under:
|
|

i have a problem about phpexcel and joomla. I'm developing some filter form to load excel reports, so i used phpexcel library to do this. Right now i have only a report, it works fine, but after that i upload inside joomla using PHP pages component that allows me to put php files inside joomla and call it.

When i put them, i change a little bit the form that calls the php that generates the excel report, i call the php using a link like this:

h**p://www.whiblix.com/index.php?option=com_php&Itemid=24

That is, calling it from Joomla, not directly the php. If i wanna call the php directly i could use this path:

h**p://www.whiblix.com/components/com_php/files/repImportaciones.php

What's the problem? The problem is, when i call the php that generates the excel through joomla, the excel that is downloaded is corrupt and only shows symbols in one cell when i open it. But if i call the php directly the report is generated fine. I could call the php directly, the problem is that if i call it directly i can't use this line of code:

defined( '_JEXEC' ) or die( 'Restricted access' );

That is used to deny the direct access to php from call it directly, because it doesn' work because the security.

Where's the problem? This is the code of php that generates the report (ommiting the code where generates the rows and cells):

    <?php
//defined( '_JEXEC' ) or die( 'Restricted access' );
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
require_once 'Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$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");
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Reporte de Importaciones');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
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;

© Stack Overflow or respective owner

Related posts about php

Related posts about joomla