<?php
/*
* excel_php.php
*
* Copyright 2009 Lucas Vieites <lucas.vieites@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/*
* Demo script that creates an html table but tells the http server it's an
* Excel file. This way the client OS can open MS Excel or OOo Calc to
* show it directly.
*/
// Generate a new filename
$filename = "testdata_" . date('Ymd') . ".xls";
// Tell the browser this is an Excel file
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
// Create some random data for the spreadsheet
$datarray = array(
"Enero" => array(rand(0,255), rand(0,255)),
"Febrero" => array(rand(0,255), rand(0,255)),
"Marzo" => array(rand(0,255), rand(0,255)),
"Abril" => array(rand(0,255), rand(0,255)),
"Mayo" => array(rand(0,255), rand(0,255)),
"Junio" => array(rand(0,255), rand(0,255)),
"Julio" => array(rand(0,255), rand(0,255)),
"Agosto" => array(rand(0,255), rand(0,255)),
"Septiembre" => array(rand(0,255), rand(0,255)),
"Octubre" => array(rand(0,255), rand(0,255)),
"Noviembre" => array(rand(0,255), rand(0,255)),
"Diciembre" => array(rand(0,255), rand(0,255))
);
// Print a simple html table.
// Excel and OpenOffice.org Calc will interpret this as a table and import it
print('<table border="1">
<th>Mes</th>
<th>Dato 1</th>
<th>Dato 2</th>');
while (list($mes, $dato) = each($datarray)) {
print("\n\t".'<tr>
<td>'.$mes.'</td>
<td>'.$dato[0].'</td>
<td>'.$dato[1].'</td>
</tr>');
}
print('
</table>');
// the end - fin - fine - het einde - qa'rI' - telda
?>