File cannot be downloaded error when exporting to xlsx using PHPExcel

Topics: Developer Forum, User Forum
May 9, 2014 at 9:23 AM
Edited May 14, 2014 at 2:11 AM
Good Afternoon.

I need help regarding exporting data to xlsx format.

I always get this error message:

<IP Address> - download.phpをダウンロードできません。

Which says that the download.php cannot be downloaded.

On the other hand, when I try to change this to xls format, I was able to download the file correctly.

here is my simple code:

<index.php>
<script>
    function ExportDataTemplate()
    {
        window.location = "download.php";
    }
    
</script>

<input type="button" class="MyButton" value="Data With Template" style="width: 150px;" onClick="ExportDataTemplate();"/>
<download.php>
<?php
include 'Classes/PHPExcel.php';
include 'Classes/PHPExcel/IOFactory.php';

error_reporting(E_ALL ^E_NOTICE);

ini_set('memory_limit', -1);
set_time_limit (0) ;

$objReader = PHPExcel_IOFactory::createReader("Excel2007"); 
$objPHPExcel = $objReader->load("Templates/tl_export_xlsx.xlsx");

$objWorksheet = $objPHPExcel->getActiveSheet();
$objPHPExcel->getDefaultStyle()->getFont()->setName('MS Pゴシック')->setSize(10);

$worksheet = $objPHPExcel->setActiveSheetIndex(0);

$newFilename = "TL_Export_". date("YmdHi").".xlsx";

$styleArray = array(
  'borders' => array(
    'allborders' => array(
      'style' => PHPExcel_Style_Border::BORDER_THIN
    )
  )
);
    
$objPHPExcel->getActiveSheet()->getStyle('A1:C1')->applyFromArray($styleArray);
    
$worksheet->setCellValueByColumnAndRow(0, 2, "1");
$worksheet->setCellValueByColumnAndRow(1, 2, "Department");
$worksheet->setCellValueByColumnAndRow(2, 2, "Team Leader");
        
unset($styleArray);
ob_clean();

header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=\"".$newFilename."\"");
header("Cache-Control: max-age=0");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); 
$objWriter->save('php://output');

?>
Thank you in advance.

By the way, I am using Linux Cent OS.
PHPExcel v1.7.6
PHP 5.3.3