marcioe Posted September 7, 2013 Report Share Posted September 7, 2013 Amigos, preciso importar dados de um TXT onde o separador é o pipe | O LAYOUT DO txt E O xls DO LAYOUT os arquivos em anexo tem apenas o carater ilustrativo. 0015000880_03092013_1733 (1).txt Quote Link to comment Share on other sites More sharing options...
joaosolution Posted September 7, 2013 Report Share Posted September 7, 2013 Marcio Boa noite Qual a dúvida? Você pode ler com a classe de ler txt, dar um append from SDF para um DBF e ler os registros. Ai você lê a string e vai comparando dbcreate("temp.dbf",{{"campo","C",1000,00}}) use temp alias temp new shared append from arq.txt sdf tmp->( dbgotop() ) while tmp->(!Eof()) xi:=1 cTxt := "" aVetor:={} for xi:=1 To Len(Alltrim(tmp->campo)) If substr(tmp->campo,xi,1) == "|" AADD( aVetor, cTxt ) cTxt :="" Else cTxt+=substr(tmp->campo,xi,1) Endif Next ? len(aVetor) tmp->(DbSkip(1)) End Neste exemplo você vai ter um vetor com os campos do arquivo em cada posição. Att João Bosco Quote Link to comment Share on other sites More sharing options...
MatheusFarias Posted September 8, 2013 Report Share Posted September 8, 2013 A Hb_ATokens funciona otimo para o que voce deseja junto com o ttxtfile veja o ex: oTxtFile = TTxtFile():New( "c:\caminho\arquivo.txt" ) // como abrir o arquivo While oTxtFile:nLine<=oTxtFile:nTLines sTexto:=oTxtFile:ReadLn() // Le a linha aTexto:=Hb_ATokens (sTexto,"|")// cria o vetor oTxtFile:Skip() // pula a linha para a proxima end assim ele vai andar em cada linha e te retornar um vetor com as posiçoes referencias http://www.freag.net/en/t/1cml3/hb_atokens http://wiki.fivetechsoft.com/doku.php?id=fivewin_class_ttxtfile Erciley Junior 1 Quote Link to comment Share on other sites More sharing options...
zekasan Posted September 9, 2013 Report Share Posted September 9, 2013 oFile:=cFile:="" cFile := cGetFile( "*.txt", cFile ) if empty(cFile) return(nil) endif if ! msgyesno("Confirma processamento do arquivo "+cFile,"ATENÇÃO") return(nil) endif ******** CANCELADOS QUANTOS:=0 QUANTOS2:=0 VALOR:=0 cFile1:=cFile+"X" oText := TTxtFile():New( cFile ) oText1=TTxtFile():New(cFile1) oText1:Open() cTotLinha:= oText:RecCount()+1 oMeter:SetRange(0,cTotLinha/100 ) oMeter:SetPos( 0 ) for n = 1 to cTotLinha cLinha:= oText:ReadLine() if substr(cLinha,1,17) ="|D100|1|0||57|02|" zLinha:= StrToken( cLinha,9, "|" ) // irá pegar o nono campo da linha lida oText1:Add(zLinha) QUANTOS+=1 endif oText:Skip() QUANTOS2+=1 oMeter:SetPos( QUANTOS2/100 ) next * oText:Close() oTExt1:close() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.