<?php include("../bd/conexion.php"); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=Inventario.xls"); header("Pragma: no-cache"); header("Expires: 0"); // Estructura HTML que Excel interpretará como tabla echo '<table border="1">'; echo '<tr> <th style="background-color: #FF8A37; color: white;">ID</th> <th style="background-color: #FF8A37; color: white;">CODIGO</th> <th style="background-color: #FF8A37; color: white;">DESCRIPCION</th> <th style="background-color: #FF8A37; color: white;">CANTIDAD</th> </tr>'; // Obtener datos de la BD $consulta_inventario = $conexion->query("SELECT CODIGO, DESCRIPCION, CANTIDAD FROM inventario"); while ($fila_inventario = $consulta_inventario->fetch_assoc()) { echo '<tr> <td>' . $fila_inventario['CODIGO'] . '</td> <td>' . $fila_inventario['DESCRIPCION'] . '</td> <td>' . $fila_inventario['CANTIDAD'] . '</td> </tr>'; } echo '</table>'; exit; ?>