I need to generate an Excel file with extension .xlsx
.
Here is my simple code:
$file = "test.xlsx";
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename='.$file);
$content = "Col1Col2Col3
";
$content .= "test1test1test3
";
$content .= "testtest1testtest2testtest3
";
echo $content;
But I get this error when I open the generated file:
Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid.
Any ideas?
See Question&Answers more detail:os