Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/10/2011, 16:29
Avatar de cristian_cena
cristian_cena
Colaborador
 
Fecha de Ingreso: junio-2009
Mensajes: 2.244
Antigüedad: 14 años, 10 meses
Puntos: 269
Respuesta: Css en Zend Framework para reporte en Excel

te comparto uno que tengo hecho, modelo y vista en un mismo archivo. verás que los estilos los doy en la tabla, luego cuando abris con excel te respeta los estilos.

Código PHP:
Ver original
  1. <?php
  2.     header("Content-type: application/vnd.ms-excel,");
  3.     header("Content-Disposition: attachment; filename=nombredelarchivo.xls");
  4.    
  5.     include("../core/abstract.db.php");
  6.     include("../core/funciones.php");
  7.    
  8.     $clave = "*********";
  9.     include("../core/mcrypt.php");
  10.    
  11.     function getTicketsUser($iduser){
  12.         $clave = "*********";
  13.         $consulta="SELECT * FROM users WHERE idusers = ".$iduser."";
  14.         $conexion  = crear_conexion(SERVER,USER,PASS); $db = DATABASE;
  15.         $resultado = consulta_base_de_datos($consulta, $db, $conexion);
  16.         if ($row = obtener_resultados($resultado))
  17.         {
  18.                 $row = desencripta($clave,$row["firstname"])." ".desencripta($clave,$row["lastname"]);     
  19.         }
  20.         return $row;
  21.     }
  22.  
  23.     $consulta="SELECT * FROM tickets";
  24.     $conexion  = crear_conexion(SERVER,USER,PASS); $db = DATABASE;
  25.     $resultado = consulta_base_de_datos($consulta, $db, $conexion);
  26.     $tikets = array();
  27.     while ($row = obtener_resultados($resultado))
  28.     {
  29.             if($row["users_idusers"]){
  30.             $row["users_idusers"] = getTicketsUser($row["users_idusers"]);
  31.             $tikets[] = $row;
  32.             }
  33.             else{
  34.             $tikets[] = $row;
  35.             }
  36.     }
  37.    
  38.     $thead = "
  39.     <table>
  40.         <tr style='background:black; color:white; font-weight:bold;'>
  41.            <th style='border:1px solid white;'>código único</th>
  42.            <th style='border:1px solid white;'>usuario</th>
  43.            <th style='border:1px solid white;'>número de ticket</th>
  44.        </tr>
  45.     ";
  46.     echo utf8_decode($thead);
  47.     foreach ($tikets as $ticket):
  48.             echo "<tr>";
  49.                 echo "<td style='border:1px solid black;'>".utf8_decode($ticket['idtickets'])."</td>";
  50.                 echo "<td style='border:1px solid black;'>".utf8_decode($ticket['users_idusers'])."</td>";
  51.                 echo "<td style='border:1px solid black;'>".utf8_decode($ticket['ticketnumber'])."</td>";
  52.             echo "</tr>";
  53.         endforeach;
  54.     echo "</table>";
  55.     cerrar_conexion($conexion);
  56.    
  57. ?>

Saludos.