enviar de php a excel
Publicado por zendi (1058 intervenciones) el 08/06/2014 22:14:54
Buenas a todos tengo este codigo el cual emite una consulta. Y mi idea es que ademas de imprimirlo en HTML, tambien sea exportado a Excel.
este es el codigo y el trozo de codigo a excel esta en negrilla e igualmente el boton.
pero me esta dando este error:
ahora no se si es que falta alguna variable.
este es el codigo y el trozo de codigo a excel esta en negrilla e igualmente el boton.
pero me esta dando este error:
1
The requested URL /tesis1/consultadeuda.php&excel was not found on this server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
if (isset($_GET['excel']))
{
header('Content-type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition: attachment; filename=oficios.xls');
header('Pragma: no-cache');
header('Expires: 0');
}
$connect = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=1234");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Consulta de la Deuda por Cédula</title>
</head>
<script language="JavaScript">
</script>
<style type="text/css">
.sr {
background-color: #FFFFCF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
</style>
<body>
<form action="consultadeuda.php" method="post">
<TABLE align="center" class="div1">
<TR>
<TD>
<SPAN CLASS='sub'>Cédula: <input TYPE="text" NAME="cedula" SIZE="10" maxlength="10">
<input TYPE="submit" NAME="buscar" VALUE="Buscar">
<input type="button" name="excel" value="Excel" onClick="location.href=location.href+'&excel'">
<INPUT TYPE="BUTTON" VALUE="Salir" ONCLICK="window.location.href='menu1.php'">
</TD>
</TR>
</TABLE>
<?php
//if ($_POST['cedula'] && $_POST['buscar']):
// $consulta2 = "SELECT * FROM vdeuda WHERE vdeuda.cedula = '{$_POST['cedula']}' ORDER BY fecha";
// $consulta3 = @pg_query($connect,$consulta2);
//endif;
//if (isset($_POST["articulo"]) && trim($_POST["articulo"]))
if ($_POST['cedula'] && $_POST['buscar'])
{
$consulta2 = "SELECT * FROM deuda WHERE deuda.cedula = '{$_POST['cedula']}' ORDER BY nroapto";
$consulta3 = @pg_query($connect,$consulta2);
}
$nombre = "SELECT apellidos,nombres FROM propietarios WHERE propietarios.cedula = '{$_POST['cedula']}'";
$nombre1 = @pg_query($connect,$nombre);
//**********************************
while ($nombre =@pg_fetch_array($nombre1)):
$apellidos = $nombre['apellidos'];
$nombres = $nombre['nombres'];
echo"<table border='1' bordercolor='#00CC99' bgcolor='#99CC00' align='center'>
<tr class='sr'>
<td width ='50' align='center'>Apellidos
<td width ='50' align='center'>Nombres
</tr>";
echo " <tr>
<td width ='100'>$apellidos</td>
<td width ='100'>$nombres</td>
</tr>
</table><br>";
endwhile;
//////////
echo"<table align='center' border='1' bordercolor='#00CC99' bgcolor='#99CC00'>
<tr>
<th width='100' align='center'>Apartamento
<th width='100' align='center'>Fecha
<th width='100' align='center'>Monto
</tr>
</table>";
//$total=0;
while($select2 = @pg_fetch_array($consulta3)):
$nroapto = $select2['nroapto'];
$nombres = $select2['nombres'];
$fecha = $select2['fecha'];
$anio = substr($fecha,0,4);
$mes = substr($fecha,5,2);
$dia = substr($fecha,8,2);
$fecha2 = $anio."-".$mes."-".$dia;
$monto = $select2['monto'];
echo"<table align='center' border='1' bordercolor='#FFCC99' bgcolor='#99CC00'>
<tr class='sr'>
<td width='100' align='center'><input type='text' value='$nroapto' readonly='true' name='nroapto'>
<td width='100' align='center'><input type='text' value='$dia"."/"."$mes"."/"."$anio' readonly='true' name='fecha'>
<td width='100' align='right'>$monto
</td>";
$total +=$monto;
endwhile;
/* if (isset($_POST['valor'])):
*/ if (isset($_POST['valor'])):
echo $totalmes = $_POST['monto']-$_POST['valor'];
if (isset($totalmes)):
$fecha2 = substr($_POST['fecha'],6,4).'-'.substr($_POST['fecha'],3,2).'-'.substr($_POST['fecha'],0,2);
$actualiza = "UPDATE deuda set monto=$totalmes WHERE deuda.cedula = '{$_POST['cedula']}' and deuda.fecha = '$fecha2'";
$connect2 = pg_connect("host=localhost port=5432 dbname=administra user=postgres password=1234");
$cambiar = @pg_query($connect2,$actualiza);
endif;
endif;
echo" </tr></table>";
echo "<br><table align='center' border='1' bordercolor='#FFCC99' bgcolor='#99CC00'>
<tr class='sr'>
<td width='100' style='color:#000000'>Total
<td width='100' align='right'>$total
</tr></table>";
?>
</form>
</body>
</html>
Valora esta pregunta


0