Foros del Web » Programando para Internet » ASP Clásico »

leer archivo de texto.

Estas en el tema de leer archivo de texto. en el foro de ASP Clásico en Foros del Web. Hola tengo un archivo ke deseo leer como texto.. tiene el formato de un html con unas tablas.. dichas tablas las kiero importar a mi ...
  #1 (permalink)  
Antiguo 07/07/2009, 08:32
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 23 años, 4 meses
Puntos: 4
leer archivo de texto.

Hola
tengo un archivo ke deseo leer como texto..
tiene el formato de un html con unas tablas..
dichas tablas las kiero importar a mi base de datos. pero no se como leer linnea por linea celda por celda de la tabla html para ir metiendo esa info en el campo ke le corresponde..

el formato de mi html seria este.


Código HTML:
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="excel_productos_archivos/filelist.xml">
<link rel=Edit-Time-Data href="excel_productos_archivos/editdata.mso">
<link rel=OLE-Object-Data href="excel_productos_archivos/oledata.mso">
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:LastAuthor>oktopus</o:LastAuthor>
  <o:LastSaved>2009-07-07T14:27:58Z</o:LastSaved>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
 {mso-displayed-decimal-separator:"\,";
 mso-displayed-thousand-separator:"\.";}
@page
 {margin:.98in .79in .98in .79in;
 mso-header-margin:0in;
 mso-footer-margin:0in;}
tr
 {mso-height-source:auto;}
col
 {mso-width-source:auto;}
br
 {mso-data-placement:same-cell;}
.style0
 {mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 white-space:nowrap;
 mso-rotate:0;
 mso-background-source:auto;
 mso-pattern:auto;
 color:windowtext;
 font-size:10.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Arial;
 mso-generic-font-family:auto;
 mso-font-charset:0;
 border:none;
 mso-protection:locked visible;
 mso-style-name:Normal;
 mso-style-id:0;}
td
 {mso-style-parent:style0;
 padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:windowtext;
 font-size:10.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Arial;
 mso-generic-font-family:auto;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 border:none;
 mso-background-source:auto;
 mso-pattern:auto;
 mso-protection:locked visible;
 white-space:nowrap;
 mso-rotate:0;}
.xl24
 {mso-style-parent:style0;
 font-weight:700;
 vertical-align:top;
 border:.5pt solid black;
 white-space:normal;}
.xl25
 {mso-style-parent:style0;
 font-weight:700;
 vertical-align:top;
 border-top:.5pt solid black;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:none;
 white-space:normal;}
.xl26
 {mso-style-parent:style0;
 font-weight:700;
 text-align:center;
 vertical-align:top;
 border-top:.5pt solid black;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:none;
 white-space:normal;}
.xl27
 {mso-style-parent:style0;
 vertical-align:top;
 border-top:none;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:.5pt solid black;
 white-space:normal;}
.xl28
 {mso-style-parent:style0;
 text-align:center;
 vertical-align:top;
 border-top:none;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:none;
 white-space:normal;}
.xl29
 {mso-style-parent:style0;
 vertical-align:top;
 border-top:none;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:none;
 white-space:normal;}
.xl30
 {mso-style-parent:style0;
 text-align:right;
 vertical-align:top;
 border-top:none;
 border-right:.5pt solid black;
 border-bottom:.5pt solid black;
 border-left:none;
 white-space:normal;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>excel_productos</x:Name>
    <x:WorksheetOptions>
     <x:DefaultColWidth>10</x:DefaultColWidth>
     <x:Selected/>
     <x:DoNotDisplayGridlines/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>11</x:ActiveRow>
       <x:ActiveCol>5</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8835</x:WindowHeight>
  <x:WindowWidth>18780</x:WindowWidth>
  <x:WindowTopX>240</x:WindowTopX>
  <x:WindowTopY>120</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body link=blue vlink=purple>
<table x:str border=0 cellpadding=0 cellspacing=0 width=1642 style='border-collapse:
 collapse;table-layout:fixed;width:1232pt' name=inicio>
 <col width=159 style='mso-width-source:userset;mso-width-alt:5814;width:119pt'>
 <col width=183 style='mso-width-source:userset;mso-width-alt:6692;width:137pt'>
 <col width=108 style='mso-width-source:userset;mso-width-alt:3949;width:81pt'>
 <col width=152 style='mso-width-source:userset;mso-width-alt:5558;width:114pt'>
 <col width=126 style='mso-width-source:userset;mso-width-alt:4608;width:95pt'>
 <col width=594 style='mso-width-source:userset;mso-width-alt:21723;width:446pt'>
 <col width=152 style='mso-width-source:userset;mso-width-alt:5558;width:114pt'>
 <col width=168 style='mso-width-source:userset;mso-width-alt:6144;width:126pt'>
 <tr height=20 style='mso-height-source:userset;height:15.0pt' name=encabezado>
  <td height=20 class=xl24 width=159 style='height:15.0pt;width:119pt'
  name="codigo_empresa">CODIGO_SAR</td>
  <td class=xl25 width=183 style='width:137pt' name="codigo_proveedor">CODIGO_PROVEEDOR</td>
  <td class=xl26 width=108 style='width:81pt' name="id_unidad">ID_UNIDAD</td>
  <td class=xl26 width=152 style='width:114pt' name=unidad>UNIDAD</td>
  <td class=xl26 width=126 style='width:95pt' name="id_producto">ID_PRODUCTO</td>
  <td class=xl25 width=594 style='width:446pt' name="nombre_producto">NOMBRE_PRODUCTO</td>
  <td class=xl25 width=152 style='width:114pt' name="precio_pesos">PRECIO_PESOS</td>
  <td class=xl25 width=168 style='width:126pt' name="precio_dolares">PRECIO_DOLARES</td>
 </tr>
 <tr height=20 style='mso-height-source:userset;height:15.0pt' name=1>
  <td height=20 class=xl27 align=right width=159 style='height:15.0pt;
  width:119pt' x:num name="codigo_empresa">1010001</td>
  <td class=xl28 width=183 style='width:137pt' name="codigo_proveedor">-</td>
  <td class=xl28 width=108 style='width:81pt' x:num name="id_unidad">2</td>
  <td class=xl28 width=152 style='width:114pt' name=unidad>UNIDAD</td>
  <td class=xl28 width=126 style='width:95pt' x:num name="id_producto">1</td>
  <td class=xl29 width=594 style='width:446pt' name="nombre_producto">WT 1
  73PULG X 15 M ANSI 150</td>
  <td class=xl30 width=152 style='width:114pt' x:num name="precio_pesos">5000</td>
  <td class=xl30 width=168 style='width:126pt' x:num name="precio_dolares">0</td>
 </tr>
 <tr height=20 style='mso-height-source:userset;height:15.0pt' name=2>
  <td height=20 class=xl27 align=right width=159 style='height:15.0pt;
  width:119pt' x:num name="codigo_empresa">1010002</td>
  <td class=xl28 width=183 style='width:137pt' name="codigo_proveedor">-</td>
  <td class=xl28 width=108 style='width:81pt' x:num name="id_unidad">2</td>
  <td class=xl28 width=152 style='width:114pt' name=unidad>UNIDAD</td>
  <td class=xl28 width=126 style='width:95pt' x:num name="id_producto">2</td>
  <td class=xl29 width=594 style='width:446pt' name="nombre_producto">WT 2 ANSI
  150 48PULG X 15'</td>
  <td class=xl30 width=152 style='width:114pt' x:num name="precio_pesos">0</td>
  <td class=xl30 width=168 style='width:126pt' x:num name="precio_dolares">3000</td>
 </tr>
 <tr height=20 style='mso-height-source:userset;height:15.0pt' name=3>
  <td height=20 class=xl27 align=right width=159 style='height:15.0pt;
  width:119pt' x:num name="codigo_empresa">1010003</td>
  <td class=xl28 width=183 style='width:137pt' name="codigo_proveedor">-</td>
  <td class=xl28 width=108 style='width:81pt' x:num name="id_unidad">2</td>
  <td class=xl28 width=152 style='width:114pt' name=unidad>UNIDAD</td>
  <td class=xl28 width=126 style='width:95pt' x:num name="id_producto">3</td>
  <td class=xl29 width=594 style='width:446pt' name="nombre_producto">WT 3 ANSI
  600 42PULG X 10'</td>
  <td class=xl30 width=152 style='width:114pt' x:num name="precio_pesos">0</td>
  <td class=xl30 width=168 style='width:126pt' x:num name="precio_dolares">500</td>
 </tr>
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=159 style='width:119pt'></td>
  <td width=183 style='width:137pt'></td>
  <td width=108 style='width:81pt'></td>
  <td width=152 style='width:114pt'></td>
  <td width=126 style='width:95pt'></td>
  <td width=594 style='width:446pt'></td>
  <td width=152 style='width:114pt'></td>
  <td width=168 style='width:126pt'></td>
 </tr>
 <![endif]>
</table>
</body>
</html>
 
 
 
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #2 (permalink)  
Antiguo 07/07/2009, 08:33
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 23 años, 4 meses
Puntos: 4
Respuesta: leer archivo de texto.

y el codigo ke estoy usando seria este..
lo lee pero no se como separar celda por celda para importarla.



Código asp:
Ver original
  1. <%
  2. detalle     = request("detalle")
  3. porfecha    = cdate(request("fecha"))
  4. principal    = "princ"
  5. contratista    = "cont"
  6. periodo        = "perio"
  7. '-------------------------- CONSULTA PARA GUARDAR DATOS -------------------------------------
  8.                         sql2 = ""
  9.                         sql2 = sql2 & " INSERT INTO rm_temp_liquidacion ( "
  10.                         sql2 = sql2 & " id_princ, "
  11.                         sql2 = sql2 & " id_cont, "
  12.                         sql2 = sql2 & " id_rm, "
  13.                         sql2 = sql2 & " id_trab, "
  14.                         sql2 = sql2 & " id_haber, "
  15.                         sql2 = sql2 & " id_descuento, "
  16.                         sql2 = sql2 & " produccion_lt, "
  17.                         sql2 = sql2 & " cuotas_lt, "
  18.                         sql2 = sql2 & " valor_lt, "
  19.                         sql2 = sql2 & " fecha_lt, "
  20.                         sql2 = sql2 & " id_usuario) "
  21.                         sql2 = sql2 & " VALUES ("
  22.                         sql2 = sql2 & " " & principal & ", "
  23.                         sql2 = sql2 & " " & contratista & ", "
  24.                         sql2 = sql2 & " " & periodo & ", "
  25. '-------------------------- CONSULTA PARA GUARDAR DATOS -------------------------------------
  26.  
  27. if 10 = 10 then
  28. on error resume next
  29. filename=server.mappath("documentos/excel_productos.xls")' aqui va la ruta del archivo que quieres cargar
  30. Set fs = CreateObject("Scripting.FileSystemObject")
  31. Set readfile=fs.OpenTextFile(filename,1,False)
  32.     if err <> 0 then
  33.         Response.Write("<hr>"&err.description&"<hr>")
  34.         Response.End()
  35.     end if
  36. linea        = 0
  37. contar      = 1
  38. ver         = 0
  39. guardafila     = ""
  40. filas        = 0
  41. Do while not readfile.atendofstream
  42.     on error resume next
  43.         if err <> 0 then
  44.             Response.Write("ERROR : "&err.description)
  45.                 exit do
  46.         else
  47. '    Text=readfile.skipline 'salta una linea
  48. '    Text=readfile.skip(74)' salta "n" numero de caracteres
  49.     Text = readfile.readline 'lee la linea en donde quedo el cursor
  50.  
  51.  if CLng(InStr(Text, "name=encabezado>")) > 0 then'---->limpia codigo para iniciar
  52.     ver = 1
  53.     Response.Write("<table border=1>")
  54.  end if
  55.  
  56.  if CLng(InStr(Text, "if supportMisalignedColumns]>")) > 0 then'---->limpia codigo para finalizar
  57.     ver = 0
  58.     Response.Write("</table>")
  59.  end if
  60.  
  61. if ver = 1 then
  62.     if CLng(instr(Text,"<tr")) <> 0 then'-------> encuentra el codigo del trabajador
  63.                 inicio_     = CLng(instr(Text,"name="))+5
  64.                 final_      = CLng(instr(Text,">"))
  65.          
  66.                 variable     = MID(Text, inicio_, final_)
  67.                 trabajador    = replace(variable,">","")
  68.                 'Response.Write("<hr>"&linea&".-"&filas&">"&trabajador)&"<br>"&vbCrLf
  69.                  
  70.                     if filas > 0 then
  71.                         sql2 = sql2 & " " & trabajador & ", "
  72.                         if isnumeric(trabajador) then
  73.                             Response.Write(sql2)&"<br>"
  74.                         end if
  75.              
  76.                     end if
  77.                  
  78.                 filas = filas + 1
  79.     else
  80. '----- recuperacion nombre variable ---------------------------------------
  81.         if CLng(instr(Text,"</td>")) <> 0 then'-------> no hay fin en la fila
  82.             if guardafila = "" then'-------> si no hay filas inconclusas continuo sin problemas
  83.                 inicio_     = CLng(instr(Text,"name="))+5
  84.                 final_      = CLng(instr(Text,"</td>"))
  85.          
  86.                 variable     = MID(Text, inicio_, final_)
  87.                 variable    = replace(variable,"</td>","")
  88.                  
  89.                 'Response.Write(linea&"."&filas&".-"&variable)&"<br>"&vbCrLf
  90.          
  91.                 guardafila = ""
  92.             else'-------> hay filas inconclusas pero hay fin asi que busco mi dato
  93.                 guardafila = guardafila&" "&Text
  94.                 inicio_     = CLng(instr(guardafila,"name="))+5
  95.                 final_      = CLng(instr(guardafila,"</td>"))-8
  96.          
  97.                 variable     = MID(guardafila, inicio_, final_)
  98.                 variable    = replace(variable,"</td>","")
  99.                 'Response.Write(linea&"."&filas&".-"&variable)&"<br>"&vbCrLf
  100.                      
  101.                 guardafila = ""
  102.             end if
  103.         else'-------> como no hay fin en la fila guardo la fila para buscar en la fila siguiente su fin
  104.             guardafila = guardafila&" "&Text
  105. '            Response.Write(guardafila)&"<BR>"
  106.         end if
  107. '----- recuperacion nombre variable ---------------------------------------
  108.     end if
  109. end if
  110. if ver = 1 then'---> visualiza codigo
  111. '        Response.Write Text& chr(13)
  112.         'Response.Write(linea)&".-"& Text& chr(13)
  113. end if
  114.  
  115.     linea = linea + 1
  116.         end if
  117. loop
  118. readfile.close
  119. set readfile=nothing
  120. set fs=nothing
  121.  
  122.     end if
  123. %>
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
  #3 (permalink)  
Antiguo 07/07/2009, 10:11
 
Fecha de Ingreso: junio-2009
Mensajes: 47
Antigüedad: 15 años, 10 meses
Puntos: 1
Respuesta: leer archivo de texto.

Lo primero que haces al abrir cualquier archivo HTML es leer TODA la informacion del archivo HTML (osea todas las etiquetas).

Luego de leido el HTML file, tienes que analizar (Parsing) la cadena de caracteres y retirar las etiquetas HTML y obtener solamente la información adecuada... claro que hacerlo de esta forma no será fácil, pero es la unica forma que se me ocurre que se puede hacer.
  #4 (permalink)  
Antiguo 08/07/2009, 07:42
Avatar de lexus  
Fecha de Ingreso: enero-2002
Ubicación: Cali - Colombia
Mensajes: 2.234
Antigüedad: 23 años, 4 meses
Puntos: 4
Respuesta: leer archivo de texto.

y tiens algun ejemplo o algo?
solo tengo lo ke mostre arriba y ya con esto me queda la tabla como tal solo me faltaria tener linea por linea y celda por celda pero eso no lo se hacer.. estoy varado en este punto.
__________________
Control de Visitantes, Control de Accesos, Minutas digitales, Manejo de Correspondencia
http://www.controldevisitantes.com
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:41.