prueba.php
Código PHP:
<?php
require_once('clsBook.php');
class ReportExcel
{
function ReportExcel()
{
}
function ShowExcel($data,$title)
{
$libro = new WorkBook();
$titulos = explode(',',$title);
$tabla = &$libro->WorkSheets[0]->Table;
//creamos el tipo de fuente
$fuente = new Font();
$fuente->FontName = 'Century Gothic';
$fuente->FontSize = 8;
$fuente->Bold = 1;
//el tipo de estilo asocido a ese fuente
$estilo = new Style('report');
$estilo->Font = $fuente;
//adicionamos
$libro->addStyle($estilo);
$fila = new Row();
$celda = new Cell("REPORTE");
$celda->StyleId = 'report';
$fila->addCell($celda);
$tabla->addRow($fila);
$fila = new Row();
$Cl=1;
foreach($titulos as $value)
{
$col = new Column();
$col->Width = 100;
$col->Index = $Cl;
$tabla->addColumn($col);
$celda = new Cell(strtoupper($value));
$celda->StyleId = 'report';
$fila->addCell($celda);
$Cl++;
}
$tabla->addRow($fila);
if (count($data) > 1){
$c=count($data);
$f=count($data[0]);
$cont=0;
while ($cont < $f)
{
$fila = new Row();
$cont1 = 0;
while ($cont1 < $c)
{
$celda = new Cell($data[$cont1][$cont]);
$fila->addCell($celda);
$cont1++;
}
$tabla->addRow($fila);
$cont++;
}
}else{
foreach($data as $Datos)
{
foreach($Datos as $valu)
{
$fila = new Row();
$celda = new Cell($valu);
$fila->addCell($celda);
$tabla->addRow($fila);
}
}
}
$libro->OutPut('attachment', 'Reporte.xls');
return;
}
}
?>