Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/05/2009, 22:29
Avatar de Shiryu_Libra
Shiryu_Libra
Colaborador
 
Fecha de Ingreso: febrero-2007
Ubicación: Cantando "Screenager" en "Kirafa Kaput"
Mensajes: 3.614
Antigüedad: 18 años, 1 mes
Puntos: 88
Respuesta: leer excel desde asp.

Lexus

te paso el archivo completo de lectura de Excel
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <%
  3. function alea(max)
  4.     dim rndmax
  5.     dim rndnumber
  6.    
  7.     rndmax = cdbl(max)
  8.     randomize timer
  9.    
  10.     rndnumber = int(rnd * rndmax)
  11.  
  12. alea = rndnumber
  13. end function
  14.  
  15. function lectura(RS)
  16.     respuesta = "<TABLE><TR><td>&nbsp;</td>"
  17.     For X = 0 To RS.Fields.Count - 1
  18.         respuesta = respuesta & "<TD>" & RS.Fields.Item(X).Name & "</TD>"
  19.     Next
  20.    
  21.     respuesta = respuesta & "</TR>"
  22.     RS.MoveFirst
  23.  
  24.     While Not RS.EOF
  25.         respuesta = respuesta & "<TR><td>"&rs.AbsolutePosition&"</td>"
  26.         For X = 0 To RS.Fields.Count - 1
  27.             respuesta = respuesta & "<TD>" & RS.Fields.Item(X).Value
  28.         Next
  29.         RS.MoveNext
  30.         respuesta = respuesta & "</TR>"
  31.     Wend
  32.     respuesta = respuesta & "</TABLE>"
  33.    
  34. lectura=respuesta
  35. end function
  36.  
  37. function insertar(sql,conn)
  38.     with conn
  39.         .execute(sql)
  40.     end with
  41.     if Err=0 then
  42.         insertar="Perfecto"
  43.     else
  44.         insertar="Mal, muy mal"
  45.     end if
  46. end function
  47.  
  48. function borrar(sql,conn)
  49.     with conn
  50.         .execute(sql)
  51.     end with
  52.     if Err=0 then
  53.         borrar="Perfecto<br />"
  54.     else
  55.         borrar="Mal, muy mal<br />"
  56.     end if
  57. end function
  58.  
  59. %>
  60. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  61. <html xmlns="http://www.w3.org/1999/xhtml">
  62. <head>
  63. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  64. <title>Documento sin t&iacute;tulo</title>
  65. </head>
  66.  
  67. <body>
  68. <!-- Begin ASP Source Code --><%
  69.  
  70. 'definiciones de uso
  71.  
  72. strcxn    =    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="&server.MapPath("ADOExcel.xls")&";Extended Properties=Excel 12.0 Xml;"
  73. strclta =     "select * from [Hoja1$] order by id_usuario"
  74. strins     =    "insert into "&_
  75.                 "[hoja1$](Nombre,Direccion,ID_Usuario,configuracion,elementos,dias)"&_
  76.             "values"&_
  77.                 "('Juliano','cajellon',"&alea(9999)&",'configuracion',"&alea(9999999)&","&alea(10)&");"
  78. strdel     =    "Delete from [hoja1$] where id_usuario = "&alea(10)&";"
  79.  
  80. response.Write strcxn & "<br />"
  81. response.Write strins & "<br />"
  82. response.Flush()
  83.  
  84. Set objConn = Server.CreateObject("ADODB.Connection")
  85. objConn.Open strcxn
  86.  
  87. Set objRS = Server.CreateObject("ADODB.Recordset")
  88. With objRS
  89.     .ActiveConnection = objConn
  90.     .CursorType = 3                    'Static cursor.
  91.     .LockType = 3                      'Pessimistic Lock.
  92.     .Source = strclta
  93.     .Open
  94. end With
  95.  
  96. %><br><%
  97.  
  98. Response.Write("Original Data")
  99. response.Write lectura(objrs)
  100. objRS.Close
  101. Set objRS = Nothing
  102.  
  103. response.Write insertar(strins,objConn)
  104. response.Write borrar(strdel,objConn)
  105.  
  106. objConn.Close
  107. Set objConn = Nothing%>
  108. <!-- End ASP Source Code -->
  109. </body>
  110. </html>
:Nota: recuerda que esta utilizando el Office 2007

si quieres volver a intentar verificando las funciones originales con tus cambios
y vuelve a postear los errores que te salgan....
__________________
"Eres parte del problema, parte de la solucion o parte del paisaje"
Un Saludo desde Desierto de Altar, Sonora, MX.
Shiryu_libra