I have a problem with my PHPExcel function. I want to generate a simple excel file for test. This works fine in my view (I found it on another website):
<?php
$objPHPExcel = new Actimage_PhpExcel();
// Create new PHPExcel object
// 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");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// 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 (Excel2007)
header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_clean();
$objWriter->save('php://output');
exit;
?>
It downloads me the correct excel file. But when I put this into my controller (sendemaildemande action), it can't download the file and response debug is displaying me some unreadable characters.
$('#listedemandes tbody').on('click', '.valider-demande', function () {
$.ajax({
url: '<?php echo $this->url(array('controller' => 'demandes', 'action' => 'sendemaildemande'),null,true);?>',
type: 'get',
datatype: 'json',
success: function(data) { alert("ok");}
});
Did I miss something ?
Thanks