1

hello i am using joomla and i am trying to create an option that the user will be able to download a csv or excel file of the table that is currently presented.

i am trying to use PHPExcel for the creation of the file. I have created an export.php file:

    {
    $objXLS = new PHPExcel();

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=File.xls"); 
header("Content-Transfer-Encoding: binary ");


    $objSheet = $objXLS->setActiveSheetIndex(0);
    //$objSheet->setCellValue(cell, value);
    $objSheet->setCellValue('A1', '1');
    $objSheet->setCellValue('A2', '2');
    $objSheet->setCellValue('A3', '3');
    $objSheet->setCellValue('A4', '4');
    $objSheet->setCellValue('A5', '5');


    $objSheet->setCellValue('B5', date('H:i:s'));

    $objXLS->getActiveSheet()->getColumnDimension("A")->setAutoSize(true);
    $objXLS->getActiveSheet()->getColumnDimension("B")->setAutoSize(true);

    $objXLS->getActiveSheet()->setTitle('Test Stats');

    $objXLS->setActiveSheetIndex(0);


    $objWriter = PHPExcel_IOFactory::createWriter($objXLS, 'Excel5');
    //$objWriter->save('php://output');
    exit;

}
}

the file gets the info of the table, inserts it into an excel sheet and outputs it to download but i am not able to access this file due to the joomla restrictions.

when i try to input the code to my model and call it the file that comes out is the entire page or the file is printed in the site page as garbage.

how do grante access to this file so i can open it in a new tab or something. or is there a simpler way to export this information to an excel file or csv using AJAX or Jquery?

thank you

Dvir Levy
  • 8,018
  • 11
  • 39
  • 60

1 Answers1

1

Your problem most likely is that the Joomla framework will output some additional HTML which is not needed for this special case; I think what you're trying to do is pretty similar to what was asked in this question. The gist is that you have to create your own action in your controller, and using and additional format=raw parameter in your URL.

Community
  • 1
  • 1
codeling
  • 11,056
  • 4
  • 42
  • 71