Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Trabajar con archivo text (https://www.clubdelphi.com/foros/showthread.php?t=57152)

Paulao 06-06-2008 15:45:17

Trabajar con archivo text
 
Seρores(as), tengo un archivo text generado ena determinada condicion. Este archivo viene muchas cosas que no me sirve, entonces necesito hacer algunos comandos para que el quede como yo gustaria, asi. O que me interesa es:
Toda las informaciones que viene apos CCF:, COO: y CONSUMIDOR:
Estas palavras no puedo cargar, solo los valores que viene luego apos las palavras. Este archivo es generado mesualmente, que puede tener tamaρos diferentes, pero estas palavras siempre viene en sus posiciones, como abajo un ejemplo de tres faturas que nosotros emitimos aca:

Cita:

FITA-DETALHE
Emissγo: 06/06/2008 10:43:39V
DATAi=01/05/2008 DATAf=06/06/2008
—————————————————————————————————————————————————————————
02/05/2008 16:25:55V CCF:001444 COO:002126
CUPOM FISCAL
ITEM CΣDIGO ST DESCRIΗΓO VL ITEM(R$)
1 00044313020076 T4 [T:5 ] CAMISA M/L S/B LISTRADO ON
1 x 63,00 63,00
——————————————————
SUBTOTAL R$ 63,00
acrιscimo 10,50
——————————————————
TOTAL R$ 73,50
A VISTA 73,50
T4=18,00%
—————————————————————————————————————————————————————————
COMPRE MAIS E PAGUE MENOS
=========================
Visite nosso Site na Internet
————————————————————————————————————————————————
—————————————————————————————————————————————————————————
[ ?(?Vh3jGJrim(BydALmcc9@1p8MQZu8CXMBkjnqrdrnJIp ]
SWEDA IF ST100
ECF-IF VERSΓO: 01.00.04 ECF: 001 LJ: 0001




FITA-DETALHE
Emissγo: 06/06/2008 10:43:39V
DATAi=01/05/2008 DATAf=06/06/2008
—————————————————————————————————————————————————————————
02/05/2008 16:26:39V CCF:001445 COO:002127
CNPJ/CPF CONSUMIDOR: 112.141.418-46
NOME: Sergio Zabeu
CUPOM FISCAL
ITEM CΣDIGO ST DESCRIΗΓO VL ITEM(R$)
1 00043997110110 T4 [T:5 ] CAMISA M/L S/B POPELINE LI
1 x 54,00 54,00
——————————————————
SUBTOTAL R$ 54,00
DESCONTO ICMS: -0,40
——————————————————
TOTAL R$ 53,60
A VISTA 53,60
T4=18,00%
—————————————————————————————————————————————————————————
COMPRE MAIS E PAGUE MENOS
=========================
Visite nosso Site na Internet
————————————————————————————————————————————————
—————————————————————————————————————————————————————————
[ gG7zDPasuC4AdyB(mvAffedaRB#m(oBT2#JiS4NC(d1oR* ]




FITA-DETALHE
Emissγo: 06/06/2008 10:43:39V
DATAi=01/05/2008 DATAf=06/06/2008
—————————————————————————————————————————————————————————
02/05/2008 16:28:25V CCF:001446 COO:002128
CNPJ/CPF CONSUMIDOR: 112.141.418-46
NOME: Sergio Zabeu
CUPOM FISCAL
ITEM CΣDIGO ST DESCRIΗΓO VL ITEM(R$)
1 00104038100099 T4 [T:48 ] BERMUDA SARJA S/P B/FACA 7
1 x 48,00 48,00
2 00023413030185 T4 [T:46M] PALETO 3 BOTOES C/ 2 ABERT
1 x 249,00 249,00
item cancelado: 2 -249,00
3 00184278030191 T4 [T:GG ] MALHA GOLA V R/10182 DIANA
1 x 96,00 96,00
4 00034005030197 T4 [T:48L] CALCA S/ PREGA BOLSO FACA
1 x 87,00 87,00
item cancelado: 4 -87,00
5 00073912120070 T4 [T:48 ] CALCA JEANS RETA TRADICION
1 x 57,00 57,00
6 00133247040075 T4 [T:G ] CUECA SLIP LIGHT S/ABERT.R
1 x 13,50 13,50
——————————————————
SUBTOTAL R$ 214,50
acrιscimo 0,50
——————————————————
TOTAL R$ 215,00
A VISTA 215,00
T4=18,00%
—————————————————————————————————————————————————————————
COMPRE MAIS E PAGUE MENOS
=========================
Visite nosso Site na Internet
————————————————————————————————————————————————
—————————————————————————————————————————————————————————
[ sG7nUwu2aARD5LMJ9teU7SLWkbUhvQMwTK5PJYVwWzFm42 ]

roman 06-06-2008 16:17:52

Hay algo que no entiendo. El texto que pones de ejemplo, ¿es de un sólo archivo o son tres? En el ejemplo que te pongo, presupongo que cada archivo tiene una sola factura:

Cσdigo Delphi [-]
procedure TForm1.LeerArchivo(Archivo: String);
var
  Lineas: TStringList;
  Linea: String;
  Token: String;
  I, N: Integer;

begin
  Lineas := TStringList.Create;

  try
    Lineas.LoadFromFile(Archivo);

    for I := 0 to Pred(Lineas.Count) do
    begin
      Linea := Lineas[i];

      N := Pos('CCF:', Linea);
      if N > 0 then
      begin
        Token := '';
        Inc(N, 4);

        while (N <= Length(Linea)) and (Linea[N] <> ' ') do
        begin
          Token := Token + Linea[N];
          Inc(N);
        end;

        txtCCF.Text := Token;
      end;

      N := Pos('COO:', Linea);
      if N > 0 then
      begin
        Token := '';
        Inc(N, 4);

        while (N <= Length(Linea)) and (Linea[N] <> ' ') do
        begin
          Token := Token + Linea[N];
          Inc(N);
        end;

        txtCOO.Text := Token;
      end;

      N := Pos('CONSUMIDOR: ', Linea);
      if N > 0 then
      begin
        Token := '';
        Inc(N, 12);

        while (N <= Length(Linea)) and (Linea[N] <> ' ') do
        begin
          Token := Token + Linea[N];
          Inc(N);
        end;

        txtConsumidor.Text := Token;
      end;
  end;
  finally
    Lineas.Free;
  end;
end;

Aquí, txtCCF, txtCOO y txtConsumidor son tres componentes TEdit.

Si un sólo archivo contiene varias facturas, habrá que hacer algunas modificaciones.

// Saludos

Paulao 06-06-2008 18:19:34

Hola, roman, estu tu codigo solo viene un solo registro. Voy a intentar a hacerlo diferente, tenendo el como base.


La franja horaria es GMT +2. Ahora son las 20:34:10.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducciσn al castellano por el equipo de moderadores del Club Delphi