PHP excel export without saving a file

PHP excel export without saving a file

-

First define a filename, and headers.

$filename = "test.xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");

Now just send the clear text data you want the excel file to contain, use “\n” and “\t” for row and column navigation.

For example:

echo "column1 \t column2\n";
echo "row1 value1" . "\t" . "row1 value2\n";
echo "row2 value1" . "\t" . "row2 value2";
exit(); //remember to stop output unless you do it its own file.

Click the excel icon below to see how the export of this data would look like.

ExcelIcon

Leave a Reply