Mira no se si te sirve, pero tengo una función que exportar una query a XLS:
//Exporta a xls
//Parametros: Query: Array con los datos a exportar
// Nombre: Nombre del archivo
public function toXLS($query, $nombre) {
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=" . $nombre . ".xls");
$objView = view\view::getInstance();
$col = $objView->getColumn();
$objView->loadHelper('String');
$xls = " ";
$xls .= "<html> ";
$xls .= "<thead> ";
$xls .= "</head> ";
$xls .= "<body>";
$xls .= "<table border=1> ";
$xls .= "<tr> ";
for ($i = 0; $i < count($col); $i++) {
$xls .= '<td>' . $objView->helper->string->stripAccents($col[$i]) . '</td> ';
}
$xls .= "</tr> ";
foreach ($query as $row) {
$xls .= "<tr> ";
for ($i = 0; $i < count($col); $i++) {
$xls .= "<td>" . $objView->helper->string->stripAccents($row[$i]) . "</td> ";
}
$xls .= "</tr> ";
}
$xls .= "</table>";
$xls .= "</body> ";
$xls .= "</html> ";
echo $xls;
}
Espero que te sirva.
Saludos