hola gracias por el codigo..
le hice estos cambios
en mi maquina me sale que no encuentra el proveedor pero si lo subo a mi hosting me sale un error diferente, yo en mi maquina uso office 2003..
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\hosting\carpeta\productos\excel_producto s.xls;Extended Properties=Excel 12.0 Xml;
Microsoft Office Access Database Engineerror '80004005' External table is not in the expected format. /compras/importar_excel.asp, line 67
Código:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
function alea(max)
dim rndmax
dim rndnumber
rndmax = cdbl(max)
randomize timer
rndnumber = int(rnd * rndmax)
alea = rndnumber
end function
function lectura(RS)
respuesta = "<TABLE><TR><td> </td>"
For X = 0 To RS.Fields.Count - 1
respuesta = respuesta & "<TD>" & RS.Fields.Item(X).Name & "</TD>"
Next
respuesta = respuesta & "</TR>"
RS.MoveFirst
While Not RS.EOF
respuesta = respuesta & "<TR><td>"&rs.AbsolutePosition&"</td>"
For X = 0 To RS.Fields.Count - 1
respuesta = respuesta & "<TD>" & RS.Fields.Item(X).Value
Next
RS.MoveNext
respuesta = respuesta & "</TR>"
Wend
respuesta = respuesta & "</TABLE>"
lectura=respuesta
end function
%>
<!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=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<!-- Begin ASP Source Code -->
<%
'definiciones de uso
strcxn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="&server.MapPath("excel_productos.xls")&";Extended Properties=Excel 12.0 Xml;"
strclta = "select * from [excel_productos$] "
'strins = "insert into "&_
' "[excel_productos$](id_unidad,id_producto,precio_pesos,precio_dolares)"&_
' "values"&_
' "('Juliano','cajellon',"&alea(9999)&",'configuracion',"&alea(9999999)&","&alea(10)&");"
' strdel = "Delete from [excel_productos$] where id_producto = "&alea(10)&";"
response.Write strcxn & "<br />"
' response.Write strins & "<br />"
response.Flush()
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strcxn
Set objRS = Server.CreateObject("ADODB.Recordset")
With objRS
.ActiveConnection = objConn
.CursorType = 3 'Static cursor.
.LockType = 3 'Pessimistic Lock.
.Source = strclta
.Open
end With
%><br><%
Response.Write("Original Data")
response.Write lectura(objrs)
objRS.Close
Set objRS = Nothing
'response.Write insertar(strins,objConn)
'response.Write borrar(strdel,objConn)
objConn.Close
Set objConn = Nothing%>
<!-- End ASP Source Code -->
</body>
</html>