Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/11/2007, 21:09
darkmcloud
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 17 años, 6 meses
Puntos: 0
Exportar una consulta asp con sql 2000 a Excel

buenas amigos de foros del web.....tengo la siguiente cosulta:
necesito que un formulario de resultados de un buscador me permita mediante un boton que no se.....diga "exportar" y me aparezca un mensaje donde diga "guardar como" y el usuario guarde el informe de la busqueda a un archivo excel...este es el codigo del buscar_clie que manda los datos a val_buscar que procesa la busqueda y muestra los resultados.....la idea mia es que esta ultima pagina, o sea val_buscar tenga el boton para exportar a excel.....este es el codigo del buscador:

BUSCAR_CLIE:
Cita:
<HTML>
<HEAD>
<p>
<title>Buscar Cliente</title>
</head>
<body BACKGROUND ="2.jpg" bgcolor="BLACK" text="BLACK" vlink="BLACK" alink="BLACK">
<font face="verdana">
<br><br><br><br><br>
</font><h2><center>
<font face="verdana"> INGRESE CSR DE Cliente </font>
</center></h2>
<font face="verdana"><center>
<form name="buscar" method="post" action="Scripts/val_buscar_clie.asp">
<font face="verdana">
<table width="824" height="173" border="0" align="center" cellpadding="0" cellspacing="5" class="clsformulario">
<td width="16" height="44">&nbsp;</td>
<td width="118">

<div align="center">
<p><font face="verdana">Csr</font> </p>
<p>
<input name="csr" style="WIDTH: 100px; HEIGHT: 22px" size=18>
</p>
</div></td>
<td width="180">
<div align="center">
<p><font face="verdana">Nombre de Cliente</font>
<input name="nombre_cliente" style="WIDTH: 150px; HEIGHT: 22px" size=80>
</p>
</div></td>
<td width="118">
<div align="center">
<p><font face="verdana">Numero de Serie </font>
<input name="serie" style="WIDTH: 100px; HEIGHT: 22px" size=18>
</p>
</div></td>

<td width="130" height="44"><div align="center"><font face="verdana">Estado</font>
<select name="estado">
<option selected></option>
<option>REVISION</option>
<option>PXR</option>
<option>SCA</option>
<option>DC</option>
<option>OK</option>
<option>ENTREGADO</option>
<option>ENPROCESO</option>
</select>
</div></td>


</table>
</font>
<TR>
<td colspan="2" align="right" valign="middle"><div align="center">
<input id=submit1 type=submit value=Aceptar name=submit1>
</div> </TR>
</form>
</td>
</tr>
</table>
<BR>
<a href="menu.asp" TARGET=_parent> Volver al Menu </a>
</center>
</font>
</body>
</html>

VAL_BUSCAR:
Cita:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<FORM ACTION='Val_buscar.asp' METHOD='GET' id=form1 name=form1>
</HEAD>
<body bgcolor="#FFCC66" background="2.jpg" text="BLACK" link="BLACK" vlink="BLACK" alink="BLACK">
<p align="center">
<%
if Session("id_usuario") = "" then
Response.Write "<SCRIPT LANGUAGE='JAVASCRIPT'>"
Response.Write "top.opener.close()"
Response.Write "</SCRIPT>"
Response.Redirect("Login.Asp")
end if

dim dbConn

'aca recibo los campos que voy a realizar la busqueda
csr = Request.form("csr")
nombre_cliente = Request.form("nombre_cliente")
serie = Request.form("serie")
estado = Request.form("estado")
tecnico = Request.form("tecnico")
On Error Resume next

Const adCmdText = &H0001
Const adOpenStatic = 3


'declaro las variables a utilizar incluyendo la se_encuentra
Dim Rs, Cnn, SQL
set Cnn=Server.CreateObject("ADODB.Connection")
set rs=Server.CreateObject("ADODB.Recordset")
Cnn.Open Session("cnx")

'ejecuto la consulta
strSQL="SELECT *, DateDiff (day, fecha_in ,fecha_ret) as difes, DATEDIFF (DAY, fecha_in, getdate()) as difftot FROM tblcliente"





se_encuentra = False

if se_encuentra then
strSQL=strSQL & " AND tipo_cliente LIKE '%cliente'"
else
strSQL=strSQL & " WHERE tipo_cliente LIKE '%cliente'"
se_encuentra=True
end if




if csr <> "" then
if se_encuentra then
strSQL=strSQL & " AND csr LIKE '%"&csr&"'"
else
strSQL=strSQL & " WHERE csr LIKE '%"&csr&"'"
se_encuentra=True
end if
end if

'la variable se_encuentra se inicializa en falso y se cambia a verdadero si el campo trae un valor ingresado

if distribuidor <> "" then
if se_encuentra then
strSQL=strSQL & " AND nombre_cliente LIKE '%"&nombre_cliente&"'"
else
strSQL=strSQL & " WHERE nombre_cliente LIKE '%"&nombre_cliente&"'"
se_encuentra=True
end if
end if


if serie <> "" then
if se_encuentra then
strSQL=strSQL & " AND serie LIKE '%"&serie&"'"
else
strSQL=strSQL & " WHERE serie LIKE '%"&serie&"'"
se_encuentra=True
end if
end if

if estado <> "" then
if se_encuentra then
strSQL=strSQL & " AND estado LIKE '%"&estado&"'"
else
strSQL=strSQL & " WHERE estado LIKE '%"&estado&"'"
se_encuentra=True
end if
end if

if tecnico <> "" then
if se_encuentra then
strSQL=strSQL & " AND tecnico LIKE '%"&tecnico&"'"
else
strSQL=strSQL & " WHERE tecnico LIKE '%"&tecnico&"'"
se_encuentra=True
end if
end if

rs.Open strSQL,Cnn,adopenstatic,adcmdtext

'abrimos la tabla para llamar los registros



if rs.EOF then
Response.Write("No existe el campo ingresado, verifique los datos")
else %>


<br>
<font face="Bookman Old Style"><em>N&uacute;mero de registros seleccionados:</em></font> <b><%=RS.RecordCount%></b>
<p align="center">
<CENTER>
<TABLE WIDTH=1000height="61" BORDER=1 align="center" CELLSPACING="0">
<tr> <td width=74 bordercolor="#F0F0F0" bgcolor="ORANGE"><center><b>Csr</b></center>
<td width=60 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Nombre Cliente</b></center>
<td width=73 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Fecha Ingreso</b></center>
<td width=122 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Artefacto</b></center>
<td width=83 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Serie</b></center>
<td width=95 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Estado</b></center>
<td width=72 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><p><b>Fecha </b><b>Status</b></p></center>
<td width=59 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Tipo de Garantia</b></center>
<td width=76 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Tecnico Asignado</b></center>
<td width=74 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Diferencia Dias Status</b></center>
<td width=74 bordercolor="#FFFFFF" bgcolor="ORANGE"><center><b>Diferencia Dias Total</b></center>
</tr> </table> </CENTER>

<%do while not rs.EOF%>

<center>
<TABLE BORDER=1 CELLSPACING="0" WIDTH=1000>
<tr>
<%Response.Write "<td WIDTH=80 align='center' >"&rs("csr")&"<td WIDTH=100 align='center'>"&rs("nombre_cliente")&"<td WIDTH=99 align='center'>"&rs("fecha_in")&"<td WIDTH=134 align='center'>"&rs("artefacto")&"<td WIDTH=100 align='center' >"&rs("serie")&"<td WIDTH=80 align='center' >"&rs("estado")&"<td WIDTH=102 align='center' >"&rs("fecha_avi")&"<td WIDTH=102 align='center' >"&rs("fecha_ret")&"<td WIDTH=70 align='center' >"&rs("gtia")&"<td WIDTH=100 align='center' >"&rs("tecnico")&"<td WIDTH=100 align='center' >"&rs("difes")&"<td WIDTH=90 align='center' >"&rs("difftot")%>
<br> </tr>
<%rs.Movenext%>
</table></center>
<%loop

end if


rs.Close

set rs = nothing

Cnn.Close

set oCnn = nothing

%>

<br> <br> <font face="Verdana">
<h3> <center> <a href="../buscar_clie.asp">Buscar Otro</a> </center> </h3>
</font>
<br> <br> <font face="Verdana">
<h3> <center> <a href="../menu.asp">Volver al Menu</a> </center> </h3>
</font>
</body>
</html>

De Antemano muchas gracias.......