How To Create Excel File With PHP

In this article, we are going to learn how to create Excel documents using PHP. Method In this method we will use a HTTP header.

You need to format the HTML and CSS using excel friendly CSS and add header information to your PHP script. Like this:

<?php
header(“Content-type:application/vnd.ms-excel”);
header(“Content-Disposition:attachment;Filename=document_name.xls”);

echo “<html>”;
echo “<meta http-equiv=”Content-Type”content=”text/html; charset=Windows-1252″>”;
echo “<body>”;
echo “<b>testdata1</b> t <u>testdata2</u> t n “;
echo “</body>”;
echo “</html>”;
?>

That’s how you can create an EXCEL file using PHP.

Template

You can download the Template here – Download