Ir para conteúdo

POWERED BY:

Arquivado

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

Ericsson Berg

PHPExcel Problemas para imprimir somente a tabela

Recommended Posts

Estou tentando usar o PHPExcel, mas estou tendo problemas!!

 

Já li a documentação, porém só consigo baixar a página toda, ao invés, da tabela que contém os dados.

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <head>
    <title>Menu Funções</title>
 <link rel="stylesheet" type="text/css" href="css.css">
  <link rel="stylesheet" type="text/css" href="form.css">
      <script type="text/javascript" src="js/jquery.js"></script>	
	
</head>   

 <body bgcolor="#CDC5BF" >
 
<input type='button' value='BOTÃO' onclick='teste()'  ></input >
 
<?php   
	  
	  // Conexão Mysql 
	  include('./Classes/PHPExcel.php');
	  error_reporting (E_ALL & ~ E_NOTICE & ~ E_DEPRECATED);
			$conecta = mysql_connect("localhost",'root', '') ; 
			if (!$conecta) {
			die('Could not connect: ' . mysql_error());
			}
	$db = mysql_select_db("empresas",$conecta) or print (mysql_error());
			
	  
	$sql0 = "SELECT empresas.empresa,
                    empresas.marca,
                    empresas.schema
              FROM empresas "; 
     
      
$result = mysql_query($sql0); 
/// Escreve resultados até que não haja mais linhas na tabela  
while($consulta = mysql_fetch_array($result)) { 

$tabela .= "<table style='border:solid 1px black;'  > 
       <thead >  
	   <tr style='border:solid 1px black;'>
         <th width='300px' >Empresa</th>
		 <th width='50px' >Apelido</th>
		</tr> 
	   </thead>
	   <tbody>
	   <tr >
	      <td >".$consulta['empresa']."</td>
		  <td >".$consulta['marca']."</td>
	   </tr>	  
	   </tbody>
   </table>";
 
}
   
//PHPExcel ------------------
$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="teste.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');

   echo $tabela;		

?>		

</body> 
<script>

</html>
 

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.