Título: leer un archivo excel con asp Publicado por: jorgexl30 en 5 Marzo 2012, 20:57 pm hola Estimados estoy con un problema ,necesito leer un archivo excel pero no en forma secuencial y no se como hacerlo ,ojala me pudieran ayudar envio el codigo
gracias de antemano Jorge <html> <body> <% 'Arreglo (0,0)=3 %> <% writeExcelData() %> </body> </html> <% function writeExcelData() Dim rs,sql,i Dim arreglo() ReDim arreglo(0,0) sql = "SELECT * FROM [hoja1$];" if runsql(sql,rs) then ROWFON = rs.Fields.Count - 1 redim arreglo (ROWFON,5) columnas = rs.Fields.Count - 1 %> <table border="1"> <thead> <tr> <% linea1="" For I = 0 To columnas linea1 = rs.Fields.Item(I).Name Response.Write "<th>" & Linea1 & "</th>" arreglo(columnas,0) = linea1 Next %> </tr> </thead> <tbody> <% contar =0 Do While Not rs.EOF Response.Write "<tr>" For I = 0 To columnas valor = rs.Fields.Item(I).Value if isnull(valor) = true then valor= " " Response.Write "<td>" & valor & "</td>" contar= contar +1 Next Response.Write "</tr>" rs.MoveNext Loop %> </tbody> </table> <% rs.Close end if Set rs = Nothing end function function runSQL(SQL,rs) on error resume next dim myrs set myRs = createobject("ADODB.recordset") myRs.Open SQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("prueba.xls") & ";Extended Properties=""Excel 8.0;IMEX=1;""", 1, 3 set rs = myRs if err then runSQL = false response.write err.description else runSQL = true end if end function %> <br> <br> como se lleno <br> <br> <% Response.Write arreglo,2 Response.End response.write arreglo,2 COL = Ubound(arreglo,2) FIL = Ubound(arreglo,1) For lnRowCounter = 0 To COL For lnColumnCounter = 0 To FIL Response.Write arreglo(lnColumnCounter, lnRowCounter) Next Next %> :huh: este es el archivo Título: Re: leer un archivo excel con asp Publicado por: jorgexl30 en 7 Marzo 2012, 15:00 pm Hola estimados e logrado leer los datos pero estoy con un problema aun no puedo meter los registros en un array bidemencional ,habra alguien que me pueda ayudar gracias este es el codigo
<html> <body> <% writeExcelData() %> </body> </html> <% function writeExcelData() Dim rs,sql,i Dim arreglo() ReDim arreglo(0,0) sql = "SELECT * FROM [hoja1$];" if runsql(sql,rs) then ROWFON = rs.Fields.Count - 1 redim arreglo (ROWFON,ROWFON) Response.Write "<table border=1><tr>" Do While Not rs.EOF Response.Write "<tr>" For I = 0 To ROWFON valor = rs.Fields.Item(I).Value if isnull(valor) = true then valor= " " 'Response.Write "<td>" & valor & "</td>" 'aca lo lleno arreglo(lnColumnCounter,I-1) = valor arreglo(I - 1 , lnRowCounter) = valor Response.Write "<td>" &arreglo(lnColumnCounter, lnRowCounter)& "</td>" Next Response.Write "</tr>" rs.MoveNext Loop COL = ubound(arreglo,2) FIL = ubound(arreglo,1) response.write "COL ("&COL&") FIL ("&FIL&")" response.write "<table>" For lnRowCounter = 0 To COL response.write "</tr>" For lnColumnCounter = 0 To FIL response.write "</td>" Response.Write arreglo(lnColumnCounter, lnRowCounter) response.write "</td>" Next response.write "</tr>" Next 'Response.Write arreglo(0,0) response.write "</table>" response.end end function function runSQL(SQL,rs) on error resume next dim myrs set myRs = createobject("ADODB.recordset") myRs.Open SQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("prueba.xls") & ";Extended Properties=""Excel 8.0;IMEX=1;""", 1, 3 set rs = myRs if err then runSQL = false response.write err.description else runSQL = true end if end function %> <br> <br> como se lleno ,se llena mostrando la variable valor mas arriba porque ? <br> <br> <% SentStr = "Four score and seven years ago our fathers brought forth" ListArray = split(SentStr, " ") response.write ubound(ListArray) COL = ubound(arreglo,2) FIL = ubound(arreglo,1) For lnRowCounter = 0 To COL For lnColumnCounter = 0 To FIL Response.Write arreglo(lnColumnCounter, lnRowCounter) Next Next %> Título: Re: leer un archivo excel con asp Publicado por: jorgexl30 en 12 Marzo 2012, 16:58 pm bueno ya que no hubo respuesta de parte de los amigos del foro aca le dejo el codigo funcionando ,por si a a alguno le interesa
<!--#INCLUDE FILE="Include/Conexion.asp" --> <html> <body> <% 'writeExcelData() %> </body> </html> <% Dim rs,sql,i Dim arreglo() ReDim arreglo(0,0) sql = "SELECT * FROM [hoja1$];" if runsql(sql,rs) then ROWFON = rs.Fields.Count - 1 redim arreglo (ROWFON+160,ROWFON) lnRowCounter=0 Do While Not rs.EOF For I =1 To ROWFON valor = rs.Fields.Item(I).Value 'aca lo lleno arreglo(lnRowCounter,I) = valor 'response.write "("&lnRowCounter&","&I&") = " & valor &"|" 'response.write arreglo(lnRowCounter,I) arreglo(I,lnColumnCounter) = valor Next lnRowCounter=lnRowCounter + 1 rs.MoveNext Loop end if 'response.End 'function writeExcelData() 'response.write arreglo(3,2) 'año 'response.write arreglo(5,2) 'rut nombre profesor 'response.write arreglo(8,2) 'codigo y nombre de la asignatura 'response.write arreglo(4,2) 'periodo 'response.write arreglo(11,2)'carrera 'response.write arreglo(16,3)'codcli 'response.write arreglo(16,4)'nombre alumno 'response.write arreglo(14,7)'fecha asistencia 'response.write arreglo(16,6)'Asistencia 'Response.Write "<br>" ' response.write arreglo(3,2) 'año 'response.write arreglo(5,2) 'rut nombre profesor 'response.write arreglo(8,2) 'codigo y nombre de la asignatura 'response.write arreglo(4,2) 'periodo 'response.write arreglo(11,2)'carrera 'response.write arreglo(17,3)'codcli 'response.write arreglo(17,4)'nombre alumno 'response.write arreglo(14,8)'fecha asistencia 'response.write arreglo(17,6)&"<br>---------"'Asistencia 'end if 'end function 'fin funcion writeExcelData() 'function guardar () ' 'Response.End if runsql(sql,rs) then for x=6 to ROWFON if arreglo(14,X)<>"" then ' Response.Write x&"<br>" 'Response.Write arreglo(40,4) for I=16 to ROWFON+160 if arreglo(I,4)<>"" then response.write arreglo(3,2) 'año response.write arreglo(4,2) 'periodo response.write arreglo(5,2) 'rut nombre profesor response.write arreglo(6,2)'segundo profesor response.write arreglo(7,2)'ayudante response.write arreglo(8,2) 'codigo y nombre de la asignatura response.write arreglo(9,2) 'sección response.write arreglo(10,2)'horas response.write arreglo(I,1)'carrera response.write arreglo(I,3)'matricula response.write arreglo(I,4)'nombre alumno response.write arreglo(14,X)'fecha asistencia response.write arreglo(I,x)&"<br>"' asistencia sql = "Insert Into ra_asistencia (ano,periodo,docente1,docente2,profayudante,codramo,descripramo,sección,horas,cod_carrera,descripcarrera,matricula,nombre,fecha,asistencia,porcentaje,Fecha_guardadatos)" sql = sql & " Values ('"&arreglo(3,2)&"','"&arreglo(4,2)&"','"&arreglo(5,2)&"','"&arreglo(6,2)&"','"&arreglo(7,2)&"','codramo','"&arreglo(8,2)&"','"&arreglo(9,2)&"','"&arreglo(10,2)&"'," sql = sql & "'"&arreglo(I,1)&"','descripcarrera','"&arreglo(I,3)&"','"&arreglo(I,4)&"','"&arreglo(14,x)&"','"&arreglo(I,X)&"','0',getdate())" Conn.Execute sql Response.write sql 'Response.End end if next end if next end if 'end function ' fin funcion guardar function runSQL(SQL,rs) on error resume next dim myrs dim nombre dim ruta nombre ="prueba.xls" ruta=Server.MapPath(nombre) set myRs = createobject("ADODB.recordset") myRs.Open SQL,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ruta & ";Extended Properties=""Excel 8.0;IMEX=1;""", 1, 3 set rs = myRs if err then runSQL = false response.write err.description else runSQL = true end if end function %> |