I needed to make a little app to make some listings in Excel and the easiest and fastest way to do it accesible to everyone was to upload it to the web. So I’ve searched how to create Excel files from PHP.

To do this I found the class IAM_XLS. With it you can create a .XLS file and add data to it (from a msql query or generating the data) and give it out to the explorer to download. Here you have an example of code:


<?php
require("iam_xls.php");

//Create EXCEL file in memory
$mid_excel = new IAM_XLS('tickets');

$i = 0;
$fila = 0;
while($i <= 50) {
//Write on cells
$mid_excel->WriteCellNumber($fila, 0, $i);
$mid_excel->WriteCellText($fila, 1, "texto");
$fila++;
$i++;
}

//Spit out the file in the browser
$mid_excel->OutputFile();

?>

Pretty simple, I had never done anything like this and in a few minutes I had it working.
It comes with enough documentation, in web format.