0
I want to generate a file .xlsx
, with records that were not imported from another table .xlsx
, but I can generate the file .xls
without problems, already when I try to generate .xlsx
, Excel warns that the file is corrupted.
Follows 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');
Internally the files . xls and xlsx are different. Only the fact that you change the extension of a valid . xls file to . xlsx already prevents Excel from opening it. xlsx among other things, "zip" the contents. The library that is using supports this file format?
– Marcus Becker
Supports, I use Phpexcel class.
– Murilo Souza