manolegal 12 Denunciar post Postado Setembro 4, 2016 Bom dia. estou tentando exportar dados html/php para excel. No meu PC funciona corretamente, porém no servidor não gera em excel, somente em html. <?php $Sql = "SELECT ....ORDER BY ..."; $Resultado = ....; echo" <table border=1 cellspacing=5 width=100%> <tr> <td><center><strong>Empresa</strong></center></td> <td><center><strong>Ano</strong></center></td> <td><center><strong>Mês</strong></center></td> </tr>"; while ($linha = pg_fetch_array($Resultado)){ $ano = $linha["ano"]; $mes = $linha["mes"]; $empresa = $linha["empresa"]; echo"<tr> <td><nobr>$empresa </nobr></td> <td><center>$ano </center></td> <td><nobr>$mes </nobr></td> </tr>"; } $nome_arquivo = "Cadastro"; 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=\"nome_arquivo.xls\"" ); header ("Content-Description: PHP Generated Data" ); ?> O arquivo gera a planilha em html e mostra a seguinte mensagem: Warning: Cannot modify header information - headers already sent by (output started at /home/meu_arquivo_tabela.php:117) in /home/meu_arquivo_tabela.php on line 180 Linha 117: </tr>"; Linha 118: while ($linha = pg_fetch_array($Resultado)){ Linha 180: header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); Compartilhar este post Link para o post Compartilhar em outros sites
Beraldo 864 Denunciar post Postado Setembro 5, 2016 Explico esse erro neste link: http://rberaldo.com.br/as-mensagens-de-erros-mais-comuns-do-php/#header Compartilhar este post Link para o post Compartilhar em outros sites
manolegal 12 Denunciar post Postado Setembro 5, 2016 Daí Beraldo, tudo certo. Seguindo sua dica, retirei a última parte do código e inclui este código antes de qualquer html ou echo e funcionou perfeitamente. Obrigado. Compartilhar este post Link para o post Compartilhar em outros sites