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

leer archivo csv con asp (codigo)

Estas en el tema de leer archivo csv con asp (codigo) en el foro de ASP Clásico en Foros del Web. tengo el siguiente codigo <% Set fs=Server.CreateObject("Scripting.FileSystemObject ") Set f=fs.OpenTextFile(Server.MapPath("cliente.csv"), 1) Function Tokenize(byVal TokenString, byRef TokenSeparators()) Dim NumWords, a() NumWords = 0 Dim NumSeps NumSeps ...
  #1 (permalink)  
Antiguo 12/08/2004, 12:32
 
Fecha de Ingreso: septiembre-2003
Mensajes: 265
Antigüedad: 21 años, 7 meses
Puntos: 1
Mensaje leer archivo csv con asp (codigo)

tengo el siguiente codigo

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject ")
Set f=fs.OpenTextFile(Server.MapPath("cliente.csv"), 1)


Function Tokenize(byVal TokenString, byRef TokenSeparators())
Dim NumWords, a()
NumWords = 0

Dim NumSeps
NumSeps = UBound(TokenSeparators)

Do
Dim SepIndex, SepPosition
SepPosition = 0
SepIndex = -1

for i = 0 to NumSeps-1

' Find location of separator in the string
Dim pos
pos = InStr(TokenString, TokenSeparators(i))

' Is the separator present, and is it closest to the beginning of the string?
If pos > 0 and ( (SepPosition = 0) or (pos < SepPosition) ) Then
SepPosition = pos
SepIndex = i
End If

Next

' Did we find any separators?
If SepIndex < 0 Then

' None found - so the token is the remaining string
redim preserve a(NumWords+1)
a(NumWords) = TokenString

Else

' Found a token - pull out the substring
Dim substr
substr = Trim(Left(TokenString, SepPosition-1))

' Add the token to the list
redim preserve a(NumWords+1)
a(NumWords) = substr

' Cutoff the token we just found
Dim TrimPosition
TrimPosition = SepPosition+Len(TokenSeparators(SepIndex))
TokenString = Trim(Mid(TokenString, TrimPosition))

End If

NumWords = NumWords + 1
loop while (SepIndex >= 0)
Tokenize = a
End Function


dim seps(1)
seps(0) = ;
dim linea 'la que lees del archivo

do while f.AtEndOfStream = false

linea = f
res=Tokenize(linea, seps)
For i=1 to UBound(res)
response.write res(i)
Response.Write("<br>")
next
'Response.Write(f.ReadLine)
'Response.Write("<br>")

loop

f.Close
Set f=Nothing
Set fs=Nothing

las funciones son de masterboy 6666 yo solo le incorpore para que me tomara el archivo csv, pero no me funciona cual puede ser el error???
  #2 (permalink)  
Antiguo 12/08/2004, 13:38
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
A ver, estoy un poco perdido con tu problema, como ya con este son tres post tuyos del mismo tema........, además nunca me ha quedado claro de que ocupas exactamente. Por ejemplo:

¿Tienes un archivo texto donde cada linea tiene por ejemplo 'este;es;un;ejemplo" y quieres guardar cada palabra en un campo diferente?
¿Es es en un mismo campo en diferentes registros?
¿Qué es lo que tienes y que es lo que deseas tener?
¿Quieres hacer algo como este sw: http://home.hccnet.nl/s.j.francke/t2t/text2table.htm?

Última edición por Myakire; 12/08/2004 a las 13:40
  #3 (permalink)  
Antiguo 12/08/2004, 13:46
 
Fecha de Ingreso: septiembre-2003
Mensajes: 265
Antigüedad: 21 años, 7 meses
Puntos: 1
perdon Myakire, porfa vor disculpame. pero e encontrado la solucion aqui esta mi codigo :
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject ")
Set f=fs.OpenTextFile(Server.MapPath("cliente.csv"), 1)

do while f.AtEndOfStream = false
linea = f.ReadLine
linea = split(linea, ";")
for i = 0 to ubound(linea)
'response.write linea(i)
next
loop

f.Close
Set f=Nothing
Set fs=Nothing
%>
lo que hace, es tomar el fichero .csv, luego mientra no sea fin de texto separo la linea con el split y muestro (linea(i)), ya que tengo esto podre hacer mis consultas o lo que quiera, dejo este codigo por si alguien lo desea....................

y myakire perdoname por no explicarme mejor mil perdon y gracias por ayudarme
nos vemos
pd: perdon
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 17:49.