Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

johnw65's avatar

Exporting to Excel without using Excel Package

Is there a way to export Excel Spreadsheet (not XML) using Laravel and not using an Excel package? Currently, I have the following code which does export , but from what I read, it's creating an XML file. So when I try to open the file, I get the following message:

 "The file format and extension of test.xls don't match.  The file could be corrupted or unsafe.  Unless you trust it's sources don't open it..."  After opening, the file format is set the Web Page (html) not xls.  

Controller:
$querydata = "sql";
$content = view('file', compact('data'));


$status = 200;
 $headers = [
'Content-Type' => 'application/vnd.ms-excel; charset=utf-8',
'Content-Disposition' => 'attachment; filename='test.xls',
 ];

	$response = response($content, $status, $headers);

0 likes
3 replies

Please or to participate in this conversation.