PHP генерирует .xlsx

Я создаю файл Excel с расширением .xlsx

Вот мой простой код для генерации

 $file = "test.xlsx";
 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
 header('Content-Disposition: attachment; filename='.$file);
 $content = "Col1\tCol2\tCol3\t\n";
 $content .= "test1\ttest1\ttest3\t\n";
 $content .= "testtest1\ttesttest2\ttesttest3\t\n";
 echo $content;

Но я получаю сообщение об ошибке при открытии сгенерированного файла.

Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid.

Я искал правильный код в течение 1 часа, но я не нашел решения.

Заранее спасибо.

Ответы на вопрос(4)

Ваш ответ на вопрос