Definitely you have to use a component to generate a Excel file. I use this lib:
- Spreadsheet::WriteExcel: A library for generating Excel Spreadsheets
- Copyright (C) 2002 Xavier Noguer [email protected]
Here is a small snippet:
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
$formato1 =& $workbook->add_format();
$formato1->set_border(1);
$formato1->set_bg_color('white');
$formato1->set_fg_color('grey');
$formato1->set_pattern();
$formato1->set_size(10);
$formato1->set_color('white');
$formato1->set_align('center');
$formato1->set_bold();
$formato2 =& $workbook->add_format();
$formato2->set_size(10);
$formato2->set_border(1);
$worksheet1 =& $workbook->add_worksheet('Relatório de Inscrições');
$linha = 1;
//Query dos dados das inscrições recebidas
$sql = "select
A.Name, A.Code
from
Customers A
order by
A.Name";
$resultado = $conn ->_execute($sql);
$worksheet1->write_string(0, 0, 'Name', $formato1);
$worksheet1->write_string(0, 1, 'Code', $formato1);
for($a = 0; $a < count($resultado); $a++)
{
$row = $resultado[$a];
$worksheet1->write_string($linha, 0, utf8_decode($row->Name), $formato2);
$worksheet1->write_number($linha, 1, $row->Code, $formato2);
$linha++;
}
$workbook->close();