Foros del Web » Programando para Internet » ASP Clásico »

Quiero pasarla a Excel o Word

Estas en el tema de Quiero pasarla a Excel o Word en el foro de ASP Clásico en Foros del Web. Estoy consultando Informacion a una BD SQL. Quiero agregar un boton para que este informe lo puedan exportar a excel o word y asi poder ...
  #1 (permalink)  
Antiguo 01/07/2003, 07:56
Avatar de dobled  
Fecha de Ingreso: enero-2002
Ubicación: Rancagua - Chile
Mensajes: 1.328
Antigüedad: 22 años, 3 meses
Puntos: 2
Quiero pasarla a Excel o Word

Estoy consultando Informacion a una BD SQL. Quiero agregar un boton para que este informe lo puedan exportar a excel o word y asi poder grabarlo,,,, tendran un codigo que quieran compartir con este pobre y humilde personaje..........
__________________
Usa títulos específicos y con sentido
En las listas de correo o en los grupos de noticias, la cabecera del mensaje es tu oportunidad de oro para atraer la atención de expertos cualificados en aproximadamente 50 caracteres o menos. No los desperdicies en balbuceos como "Por favor ayúdame" (de "POR FAVOR AYÚDAME!!!" ya ni hablamos). No intentes impresionarnos con lo profundo de tu angustia; mejor usa ese preciado espacio para una descripción lo más concisa posible del problema.
  #2 (permalink)  
Antiguo 01/07/2003, 15:24
 
Fecha de Ingreso: noviembre-2001
Ubicación: Groningen
Mensajes: 175
Antigüedad: 22 años, 6 meses
Puntos: 0
Hola Dobled,

si buscas en Google, vas a encontrar montones de ejemplos de como generar una planilla de excel, por medio de vbscrip o jscript.

saludos
ed
  #3 (permalink)  
Antiguo 01/07/2003, 18:25
Avatar de Gurrutello  
Fecha de Ingreso: enero-2002
Ubicación: Ontario,Toronto [Canada]
Mensajes: 2.017
Antigüedad: 22 años, 3 meses
Puntos: 6
hola
como antes te dijeron no esta mal que buscara sun poquito pero weno
esta en ingles
Código PHP:
<html>
<
title>CodeAve.com(Create Word On Server)</title>
<
body bgcolor="#FFFFFF">
<%
' Name of the access db being queried
accessdb="state_info" 

Connection string to the access db
cn
="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn "DBQ=" Server.MapPath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

Query the states table from the state_info db
sql 
"select state,statename,capital,year,order from states " 

' Execute the sql
rs.Open sql, cn

Move to the first record
rs
.MoveFirst

' For net loop to create seven word documents from the record set
change this to "do while not rs.eof" to output all the records
' and the corresponding next should be changed to loop also

For documents= 1 To 7
Creates a text file on the server with the state abbreviation 
' as the name for the ouput document 
file_being_created= rs("state") & ".doc"

create a file system object
Set fso 
CreateObject("scripting.filesystemobject")

' create the text file - true will overwrite any previous files
Set act = fso.CreateTextFile(Server.MapPath(file_being_created), True)

Writes the db output to a .doc file in the same directory 
act
.WriteLine("<html><title>CodeAve.com(" rs("statename") & " State Info)</title>")
act.WriteLine("<body bgcolor='#FFFFFF'> " )
act.WriteLine("State: " rs("statename") & "<br>" )
act.WriteLine("Abbreviaton: " rs("state") & "<br>" )
act.WriteLine("Capital: " rs("capital") & "<br>")
act.WriteLine("Entered the Union in "rs("year") & "<br>")
act.WriteLine("Number in order of entrance into the Union "rs("order") & "<br>")
act.WriteLine("Page created on: " Now ())
act.WriteLine("</body></html>")

' close the object
act.close

Writes the links to the newly created pages in the browser
Response
.Write "<a href='" rs("state") & ".doc'>" rs("statename") & "</a> (.doc) &nbsp;" Now() & "<br>"

' move to the next record
rs.movenext

return to the top of the for - next loop
' change this to "loop" to output all the records
and the corresponding for statement above should be changed also
Next
%>
</
body>
</
html
a ver si te sirve es para convertir a word
saludos
  #4 (permalink)  
Antiguo 01/07/2003, 18:28
Avatar de Gurrutello  
Fecha de Ingreso: enero-2002
Ubicación: Ontario,Toronto [Canada]
Mensajes: 2.017
Antigüedad: 22 años, 3 meses
Puntos: 6
aqui va el de excel
Código PHP:
<%
'comprobamos si introducimos un titulo
u_title=Request.Form("u_title")
If u_title = "" Then
%>
<html>
<body bgcolor="#FFFFFF">
<!-- Formulario - Solo será ,mostrado si no ingrasamos un titulo -->
<form method="POST" action="<%= request.servervariables("script_name") %>">
Titulo del documento<br>
<Input Type="text" name="u_title" size="35">
<br><br>
Cell 1
<br>
<textarea rows="2" name="u_cell1" cols="35"></textarea>
<br><br>
Cell 2
<br>
<textarea rows="2" name="u_cell2" cols="35"></textarea>
<Input Type="submit" value="Submit" ></p>
</form>
<%
Else

Si se introdujo un titulo
' Obtenemos todos los valores
u_title=Request.Form("u_title")
u_cell1=Request.Form("u_cell1")
u_cell2=Request.Form("u_cell2")

Varible created fo excel file nameSpeces are changed to underscores
' and later the current date is added in attempts to create a unique file
Users are not prevented from entering characters !@#$%^&*()+= that are 
' invlaid file names in this example
g_filename=Replace(u_title," ","_")


Set fso = CreateObject("scripting.filesystemobject")
create the text (xlsfile to the server adding the -mmddyyyy after the g_title value
Set act 
fso.CreateTextFile(Server.MapPath(""&g_filename "-"Month(Date())& Day(Date())& Year(Date()) &".xls"), True)

' write all of the user input to the text (xls) document 
The .xls extension can just as easily be .asp or .inc whatever best suits your needs
' Providing that you remove the info contained in the header and remove the xml
reference in the html tag that starts the page/excel fileIt is to add gridlines and
' a title to the excel worksheet
act.WriteLine "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">"
act.WriteLine "<head>"
act.WriteLine "<!--[if gte mso 9]><xml>"
act.WriteLine "<x:ExcelWorkbook>"
act.WriteLine "<x:ExcelWorksheets>"
act.WriteLine "<x:ExcelWorksheet>"
act.WriteLine "<x:Name>"& u_title &"</x:Name>"
act.WriteLine "<x:WorksheetOptions>"
act.WriteLine "<x:Print>"
act.WriteLine "<x:ValidPrinterInfo/>"
act.WriteLine "</x:Print>"
act.WriteLine "</x:WorksheetOptions>"
act.WriteLine "</x:ExcelWorksheet>"
act.WriteLine "</x:ExcelWorksheets>"
act.WriteLine "</x:ExcelWorkbook>"
act.WriteLine "</xml>"
act.WriteLine "<![endif]--> "
act.WriteLine "</head>"
act.WriteLine "<body>"
act.WriteLine "<table>"
act.WriteLine "<tr>"
act.WriteLine "<td>"
act.WriteLine u_cell1
act.WriteLine "</td>"
act.WriteLine "<td>"
act.WriteLine u_cell2
act.WriteLine "</td>"
act.WriteLine "</tr>"
act.WriteLine "</table>"
act.WriteLine "</body>"
act.WriteLine "</html>"
close the document 
act
.close
%>
Your excel has been successfully create And can be viewed by clicking 
<a href="<%= g_filename &"-"& month(date())& day(date())& year(date()) %>.xls" target="_blank">here</a>
<%
 
end check of form input
End 
If
%>
</
body>
</
html
tambien en ingles
adaptalos a tus necesidades y despues cuentas
pd. obtenidos desde tutores.org( proximamente ) aunque de obtenidos desde diferentes usuarios y seran traducidos a español
saludos
  #5 (permalink)  
Antiguo 02/07/2003, 04:01
Avatar de angel_dope  
Fecha de Ingreso: noviembre-2002
Ubicación: Valencia
Mensajes: 737
Antigüedad: 21 años, 5 meses
Puntos: 8
Te pongo otro para excel en Spanish y por lo que veo más corto que lo que ya hay. Eso si, con esto lo que hace es crearte un fichero excel en el servidor. Eso no siempre puede ser recomendable. Yo lo he hecho asi, por que es lo que necesito en mi aplicación, yo quiero que los excel generados se conserven y se los puedan descargar los usuarios para un uso posterior

Código PHP:
<%@LANGUAGE="VBSCRIPT"%>
<!--
#include file="Connections/Gestom.asp" -->
<%
'Creas el recordset. Si no trabajas con DSN, hay que crear primero la conexión

Dim Empresas__MMColParam
Empresas__MMColParam = "1"
if (Request.QueryString("NOla") <> "") then Empresas__MMColParam = Request.QueryString("NOla")
%>
<%
Dim Empresas__MMColParamB
Empresas__MMColParamB = "1"
if (Request.Querystring("anyo")  <> "") then Empresas__MMColParamB = Request.Querystring("anyo") 
%>
<%
set Empresas = Server.CreateObject("ADODB.Recordset")
Empresas.ActiveConnection = MM_Gestom_STRING
Empresas.Source = "SELECT Cluster, Cuenta  FROM lis_empresas_recibidas  WHERE NOla = '" + Replace(Empresas__MMColParam, "'", "''") + "' 
AND año " + Replace(Empresas__MMColParamB, "'", "''") + ""
Empresas.CursorType = 0
Empresas.CursorLocation = 2
Empresas.LockType = 3
Empresas.Open()
Empresas_numRows = 0

Se crean las variables a utilizar (PathXXX corresponde a la ruta
' del archivo de tipo XXX que utilizaremos).
PathXLS        = Server.MapPath("./exportacion/Listado_empresas_recibidas_nola_"&Request.querystring("nola")&"_anyo_"&Request.querystring("anyo")&".xls")
FinLinea       = ""

Creo los objetos que utilizaremosserán de los tipos FSOTextStream y Connection
If not empresas.eof then
Set fso        
Server.CreateObject("Scripting.FileSystemObject")
Set Arch_Excel fso.CreateTextFile(PathXLSTrue)
'Set oConn      = Server.CreateObject("ADODB.Connection")


Recorro todo el recordset recuperando sus valores y escribiéndolos en el archivo Excel
If not empresas.bof or not empresas.eof then empresas.MoveFirst
'Aqui le metes la primera linea, con los encabezados de los campos para que despues sepas que hay en cada columna. 
'
Es muy importante que el orden de los campos de la select coincida con el orden de lo que pones aqui en el encabezado
'ya que sino, no te coincidirán los datos con el encabezado.
'
El chr(9es para pasar a la siguiente columna
encabezado 
"Cluster" chr(9) &"Cuenta" 
Arch_Excel.writeline encabezado
Do while Not empresas.EOF
    FinLinea 
""
    
For each x in empresas.fields
        FinLinea 
FinLinea x.value chr(9)
    
Next
    Arch_Excel
.writeline FinLinea
empresas
.MoveNext
Loop



' Cierro y destruyo todos los objetos utilizados para liberar memoria del servidor
Arch_Excel.Close
Set Arch_Excel = Nothing
Set fso        = Nothing
end if
%>
'
Despues creas la página con un enlace para poder abrir y descargar
<html>
<
head>
<
title>Untitled Document</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</
head>
<
body bgcolor="#0099CC" text="#000000">
<%
enlace "./exportacion/Listado_empresas_recibidas_nola_"&Request.querystring("nola")&"_anyo_"&Request.querystring("anyo")&".xls"%>
<
p><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF"><b>El 
  listado se ha generado correctamente en una hoja Excel
.</b></font></p>
<
p><font color="#FFFFFF"><b><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="<%=enlace%>">Descargar 
  archivo Excel Generado
</a></font></b></font></p>
<
p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><font color="#FFFFFF">(NOTA
  
Para descargar el archivo debe pulsar el enlace con el boton derecho y seleccionar 
  
&quot;Guardar Como&quot;)</font></b></font></p>
</
body>
</
html>
<%
Empresas.Close()
%> 
__________________
Vayamos por Partes :: Jack el Destripador

Última edición por angel_dope; 02/07/2003 a las 04:08
  #6 (permalink)  
Antiguo 02/07/2003, 07:03
Avatar de dobled  
Fecha de Ingreso: enero-2002
Ubicación: Rancagua - Chile
Mensajes: 1.328
Antigüedad: 22 años, 3 meses
Puntos: 2
Gracias los probare enseguida
__________________
Usa títulos específicos y con sentido
En las listas de correo o en los grupos de noticias, la cabecera del mensaje es tu oportunidad de oro para atraer la atención de expertos cualificados en aproximadamente 50 caracteres o menos. No los desperdicies en balbuceos como "Por favor ayúdame" (de "POR FAVOR AYÚDAME!!!" ya ni hablamos). No intentes impresionarnos con lo profundo de tu angustia; mejor usa ese preciado espacio para una descripción lo más concisa posible del problema.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:51.