Call phpexcel from joomla

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://www.whiblix.com/index.php?option=com_php&Itemid=24

That is, calling it from Joomla, and not directly php. If I want to call php directly, I can use this path:

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

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
//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;
+3
source share
2 answers

PHPExcel-Joomla-Library

Joomla, , . github. Joomla! 2.5 3

.

+3

Joomla PHPExcel Joomla PHPExcel Joomla PHPExcel.

0

All Articles