Hola Jorge, mira esto te puede servir
<?php
include("conexion.php"); //aca van tus funciones de conexion a la base de datos
$date_month = date('m');
$date_year = date('Y');
$date_day = date('d');
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=clientes.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
$sql = "SELECT * FROM cliente";
$rs=pg_query($conexion,$sql);
?>
<table border="1" align="center">
<tr align="center">
<th>Codigo</th>
<th>Nombre</th>
</tr>
<?php
while($registro=pg_fetch_array($rs))
{ ?>
<tr>
<td><?php echo $registro[0]; ?> </td>
<td><?php echo $registro[1]; ?> </td>
</tr>
<?php } ?>
</table>
saludos
Jose Aspíllaga