Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

LilianFreitas123

Exportar tabela HTML para Excel usando PHP

Recommended Posts

Boa tarde,

 

Estou tentando exportar a tabela abaixo para Excel usando PHP, porém não estou conseguindo. Alguém teria alguma dica?

<table class="table table-bordered table-striped" >
                  <thead>
							     <tr>
                      <th style="text-align:center" colspan="4"><?php echo $stm->descricao; ?></th>
                    </tr>              
                  </thead>
                  <?php $service = new MetaOrcamentoService();
                  $line = $service->getRelatorio($lista->idprojeto,$stm->iditem); ?>
                  <tbody>
                  <?php foreach ($line as &$listagem) { ?>

                    <tr>
                      <td></td>
                      <td style="font-weight:bold; text-align:center">Real</td>
                      <td style="font-weight:bold; text-align:center">Dolares</td>
                      <td style="font-weight:bold; text-align:center">Euros</td>
                    </tr>
                    <tr>
                      <td style="font-weight:bold"><?php echo $listagem->descricaoLinha; ?></td>
                      <td style="text-align:right">R$ <?php echo $listagem->vlr_real; ?></td>
                      <td style="text-align:right">$ <?php echo $listagem->vlr_dolar; ?></td>
                      <td style="text-align:right">€ <?php echo $listagem->vlr_euro; ?></td>
                    </tr>
                    <tr>
                      <?php } ?> 
                    <tr>
                      <td colspan="4"> </td>
                    </tr>
                  </tbody>
                   
                </table>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Lilian Freitas.

  //download Excel
  $arquivo = "relatorio.xls";
  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" );

Adicione isto no seu arquivo .php

 

Atenciosamente,

Vitor M. Braga.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.