PHPExcel generates corrupted .xslx file

0

I want to generate a .xlsx file, with the records that were not imported, from another table .xlsx , however I can generate the .xls file without problems, when I try to generate .xlsx , Excel warns that the file is corrupted.

Follow the code:

$php_excel->setActiveSheetIndex(0)
      ->setCellValue('A' . $linha_php_excel, $row[CPF])
      ->setCellValue('B' . $linha_php_excel, $row[NOME])
      ->setCellValue('C' . $linha_php_excel, $row[NR_CONTRATO])
      ->setCellValue('D' . $linha_php_excel, $row[DATA_CONTRATO])
      ->setCellValue('E' . $linha_php_excel, $row[PRODUTO])
      ->setCellValue('F' . $linha_php_excel, $row[OBS_CONTRATO])
      ->setCellValue('G' . $linha_php_excel, $row[PARCELA])
      ->setCellValue('H' . $linha_php_excel, $row[VALOR])
      ->setCellValue('I' . $linha_php_excel, $row[VALOR])
      ->setCellValue('J' . $linha_php_excel, $row[OBS_PARCELA])
      ->setCellValue('K' . $linha_php_excel, 'Registro já existe');
$php_excel->getActiveSheet()->getStyle('K' . $linha_php_excel)
      ->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
$linha_php_excel++;

Header :

$objWriter = PHPExcel_IOFactory::createWriter($php_excel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="teste.xlsx"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
    
asked by anonymous 20.01.2017 / 13:39

1 answer

2

It would look like this ...

header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="teste.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($php_excel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
    
20.01.2017 / 14:12