Ver Mensaje Individual
  #31 (permalink)  
Antiguo 05/06/2009, 16:56
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
Respuesta: leer un excel exportado desde asp.

ASI SE LEE EL EXCEL, LAS VARIABLES CONTIENEN LOS DATOS, EN ESTE CASO LAS MUESTRO EN PANTALLA PARA ANALIZAR PRIMERO SI COMETO UN ERRROR.


Código PHP:
<html>
<
head>
<
title>LEER EXCEL</title>
<
style type="text/css">
<!--
.
Estilo3 {font-familytahoma}
.
Estilo9 {
    
font-size18px;
    
font-weightbold;
    
color#FFFFFF;
}
-->
</
style>
</
head>

<
body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<
br><br>


<
center>

<%

detalle     request("detalle")
porfecha    cdate(request("fecha"))

principal    "princ"
contratista    "cont"
periodo        "perio"

'-------------------------- CONSULTA PARA GUARDAR DATOS -------------------------------------
                        sql2 = ""
                        sql2 = sql2 & " INSERT INTO rm_temp_liquidacion ( "
                        sql2 = sql2 & " id_princ, "
                        sql2 = sql2 & " id_cont, "
                        sql2 = sql2 & " id_rm, "
                        sql2 = sql2 & " id_trab, "
                        sql2 = sql2 & " id_haber, "
                        sql2 = sql2 & " id_descuento, "
                        sql2 = sql2 & " produccion_lt, "
                        sql2 = sql2 & " cuotas_lt, "
                        sql2 = sql2 & " valor_lt, "
                        sql2 = sql2 & " fecha_lt, "
                        sql2 = sql2 & " id_usuario) "

                        sql2 = sql2 & " VALUES ("
                        sql2 = sql2 & " " & principal & ", "
                        sql2 = sql2 & " " & contratista & ", "
                        sql2 = sql2 & " " & periodo & ", "
'
-------------------------- CONSULTA PARA GUARDAR DATOS -------------------------------------



if 
10 10 then

on error resume next
filename
=server.mappath("nombre_archivo.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


 
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
    ver 
0
    Response
.Write("</table>")
 
end if


if 
ver 1 then

    
if CLng(instr(Text,"<tr")) <> 0 then'-------> encuentra el codigo 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

%>

<%
fin_imprimir%>

</
center>

</
body>
</
html
__________________
Atte,
A n g e l u s
Concepción - Chile
más vale respuestas bien pensadas, que 7000 post