Ver Mensaje Individual
  #19 (permalink)  
Antiguo 29/05/2009, 23:27
Avatar de a n g e l u s
a n g e l u s
 
Fecha de Ingreso: enero-2006
Ubicación: Chile
Mensajes: 237
Antigüedad: 19 años, 3 meses
Puntos: 1
Recupera datos

RECUPERAR DATOS DEL EXCEL GENERADO POR ASP:

Código PHP:
<%
on error resume next
filename
=server.mappath("planillaexcelgeneradaconasp.xls")' aqui va la ruta del archivo que quieres cargar

Set fs = CreateObject("Scripting.FileSystemObject")
Set readfile=fs.OpenTextFile(filename,1,False)

    if err <> 0 then
        Response.Write("<hr>"&err.description&"<hr>")
        Response.End()
    end if

linea        = 0
contar      = 1
ver         = 0
guardafila     = ""
filas        = 0

Do while not readfile.atendofstream
    on error resume next
        if err <> 0 then
            Response.Write("ERROR : "&err.description)
                exit do
        else
'    
Text=readfile.skipline 'salta una linea
'    
Text=readfile.skip(74)' salta "n" numero de caracteres
    Text = readfile.readline '
lee la linea en donde quedo el cursor

'solo tomara los datos de la tabla y omite todo el resto que no sirve
 if CLng(InStr(Text, "name=encabezado>")) > 0 then'
---->limpia codigo para iniciar
    ver 
1
    Response
.Write("<table border=1>")
 
end if
 
 if 
CLng(InStr(Text"if supportMisalignedColumns]>")) > 0 then'---->limpia codigo para finalizar, aqui revisa codigos agrega excel para quitarlos
    ver = 0
    Response.Write("</table>")
 end if


if ver = 1 then'
-->IMPRIMIR EL CODIGO PARA VERLO COMO TABLA

    
if CLng(instr(Text,"<tr")) <> 0 then'-------> encuentra el ID del trabajador
                inicio_     = CLng(instr(Text,"name="))+5
                final_      = CLng(instr(Text,">"))
        
                variable     = MID(Text, inicio_, final_)
                trabajador    = replace(variable,">","")
                Response.Write("<hr>"&linea&".-"&filas&">"&trabajador)&"<br>"&vbCrLf
                
                    if filas > 0 then

                        sql2 = sql2 & " " & trabajador & ", "

                        if isnumeric(trabajador) then
                            Response.Write(sql2)&"<hr>"
                        end if
            
                    end if
                
                filas = filas + 1
    else

'
----- recuperacion nombre variable ---------------------------------------
        if 
CLng(instr(Text,"</td>")) <> 0 then'-------> no hay fin en la fila
            if guardafila = "" then'
-------> si no hay filas inconclusas continuo sin problemas
                inicio_     
CLng(instr(Text,"name="))+5
                final_      
CLng(instr(Text,"</td>"))
        
                
variable     MID(Textinicio_final_)
                
variable    replace(variable,"</td>","")
                
                
Response.Write(linea&"."&filas&".-"&variable)&"<br>"&vbCrLf
        
                guardafila 
""
            
else'-------> hay filas inconclusas pero hay fin asi que busco mi dato
                guardafila = guardafila&" "&Text
                inicio_     = CLng(instr(guardafila,"name="))+5
                final_      = CLng(instr(guardafila,"</td>"))-8
        
                variable     = MID(guardafila, inicio_, final_)
                variable    = replace(variable,"</td>","")

                Response.Write(linea&"."&filas&".-"&variable)&"<br>"&vbCrLf
                    
                guardafila = ""
            end if
        else'
-------> como no hay fin en la fila guardo la fila para buscar en la fila siguiente su fin
            guardafila 
guardafila&" "&Text
'            Response.Write(guardafila)&"<BR>"
        end if
'
----- recuperacion nombre variable ---------------------------------------
    
end if
end if

if 
ver 1 then'---> visualiza codigo
'        
Response.Write Textchr(13)
        
Response.Write(linea)&".-"Textchr(13)
end if


    
linea linea 1
        end 
if

loop
readfile
.close
set readfile
=nothing

set fs
=nothing



    end 
if

%> 


Espero haber ayudado con este código, si se puede mejorar lo agregan aca.
__________________
Atte,
A n g e l u s
Concepción - Chile
más vale respuestas bien pensadas, que 7000 post