Ver Mensaje Individual
  #4 (permalink)  
Antiguo 14/08/2009, 07:29
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 15 años
Puntos: 1517
Respuesta: Php Excel y Base de Datos

No te preocupes no me he ofendido. Pero mientras tanto puedes hacerlo de esta forma, que no es la que te sugiero sino que busques sobre la clase que te indique. Con el PHPExcel siempre trata los ejemplos que te dan y luego modifícalo a tus necesidades. Pero aqui tienes un ejemplo diferente a PHPExcel

Código php:
Ver original
  1. <?php
  2. header("Pragma: public");
  3. header("Expires: 0");
  4. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5. header("Content-Type: application/force-download");
  6. header("Content-Type: application/octet-stream");
  7. header("Content-Type: application/download");
  8. header("Content-Type: application/vnd.ms-excel");
  9. header('Content-Disposition: attachment; filename="nombre.xls"');
  10.  
  11.  
  12. $s = "SELECT * FROM tabla";
  13. $r = mysql_query($s);
  14.  
  15. $bodyTable = "<tr>
  16.         <th NOWRAP>Employee Number</th>
  17.         <th NOWRAP>Transaction Code</th>
  18.         <th NOWRAP>Date</th>
  19.         <th NOWRAP>Count</th>
  20.     </tr>";
  21. while($row = mysql_fetch_assoc($r)){
  22.     $bg=($bg=='E2E2F2'?'F2F2FF':'E2E2F2');
  23.     $bodyTable .= "<tr>
  24.         <td bgcolor='#".$bg."' NOWRAP align='center'>".$row["columna1"]."</td>
  25.         <td bgcolor='#".$bg."' NOWRAP align='center'>".$row["columna2"]."</td>
  26.         <td bgcolor='#".$bg."' NOWRAP align='center'>".$row["columna3"]."</td>
  27.         <td bgcolor='#".$bg."' NOWRAP align='center'>".$row["columna4"]."</td>
  28.     </tr>";
  29. }
  30.  
  31. $setBody = <<< BHD
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
  34. <head>
  35.     <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
  36. </head>
  37. <body>
  38.  
  39. <div id="MainExcelDiv" align="center" x:publishsource="Excel">
  40. <table x:str border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
  41. {$bodyTable}
  42. </table>
  43. </div>
  44. </body>
  45. </html>
  46. BHD;
  47.  
  48. echo $setBody;

Tambien te añado que lo mejor es trabajar con CSV, no se si lo has pensando usar o si es obligado usar xls.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos

Última edición por abimaelrc; 14/08/2009 a las 07:56