Creare file excel in PHP è altrettanto semplice come creare file word con php, tutto sta nel dichiarare la giusta intestazione.
Una volta creato il file excel.php lo si potrà potrà "popolare" con dati provenienti da un dabase mysql, da un file XML, da un form o da qualsiasi altrà fonte si voglia, basterà adeguare alle proprie necessità il prossimo esempio:
<?php $nomefile= "excel.xls"; header ("Content-Type: application/vnd.ms-excel"); header ("Content-Disposition: inline; filename=$nomefile"); ?> <table border="1"> <?php for ($i=1; $i<10; $i++) { echo "<tr>"; for ($x=1; $x<10;$x++) { $r = $i * $x; echo "<td>$r</td>"; } echo "</tr>"; } ?> </table>
Grazie al MIME-Type application/vnd.ms-excel il file excel.php si trasformerà in un normalissimo file excel che potremmo "aprire al volo" o semplicemente salvare sul computer.