开发者

Call phpexcel from joomla

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.")
  开发者_JAVA技巧                           ->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;


PHPExcel-Joomla-Library

I've build a library for Joomla, which will make the whole process on installing, using and updating it more easy. You can check it out on github. It's available for Joomla! 2.5 and 3

Feedback is welcome.


There's a lot of information on the Joomla forums about using PHPExcel with Joomla and on the PHPExcel board about fixing a clash between the Joomla and PHPExcel autoloaders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜