[Resolvido] Gerar um arquivo excel apos a consulta
Bom dia a todos, estou fazendo uma consulta no banco e gostaria que apos a consulta gerasse um arquivo excel, fiz o código ele não esta retornando nenhum erro porem não gera o arquivo em excel se alguem puder me ajudar eu agradeço
segue o código
<?php
$arquivo = 'usuarios.xls';
$query = "SELECT * FROM user ORDER BY usoNome";
$resultado = mysql_query($query) or die ("Erro: Não foi possível realizar a consulta");
$html = '';
$html .= '<table border=1>';
$html .= '<tr>';
$html .= '<td colspan=5 align=center><b>CADASTRO DE USUÁRIOS</b></tr>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td><b>Nome</b></td>';
$html .= '<td><b>Endereço</b></td>';
$html .= '<td><b>Bairro</b></td>';
$html .= '<td><b>Cidade</b></td>';
$html .= '<td><b>Estado</b></td>';
$html .= '<td><b>CEP</b></td>';
$html .= '<td><b>Fone</b></td>';
$html .= '<td><b>D.N.</b></td>';
$html .= '<td><b>Sexo</b></td>';
$html .= '<td><b>Email</b></td>';
$html .= '</tr>';
while($campo = mysql_fetch_array ($resultado)){
$nome = $campo['usoNome'];
$rua = $campo['usoEndereco'];
$bairro = $campo['usoBairro'];
$cidade = $campo['usoCidade'];
$estado = $campo['usoEstado'];
$cep = $campo['usoCEP'];
$fone = $campo['usoTelefone'];
$dn = $campo['usoDia'];
$sexo = $campo['usoSexo'];
$email = $campo['usoEmail'];
$html .= '<tr>';
$html .= '<td>' . $nome . '</td>';
$html .= '<td>' . $rua . '</td>';
$html .= '<td>' . $bairro . '</td>';
$html .= '<td>' . $cidade . '</td>';
$html .= '<td>' . $estado . '</td>';
$html .= '<td>' . $cep . '</td>';
$html .= '<td>' . $fone . '</td>';
$html .= '<td>' . $dn . '</td>';
$html .= '<td>' . $sexo . '</td>';
$html .= '<td>' . $email . '</td>';
$html .= '</tr>';
}
$html .= '</table>';
echo "$html";
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=\"{$arquivo}\"" );
header("Content-Description: PHP Generated Data" );
?>Discussão (6)
Carregando comentários...