unit ApriDati;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, dbf, dbf_common, dbf_fields;

var
  G1Path : String;
  ExPath : String;
  DbfXOpe: TDbf; //File di configurazione interfaccia

implementation

procedure CaricaLibro(Form1:TForm1);
var
  i: Integer;
  DbfBook0: TDBF;
  Ws1Name: String;

begin
      //G1Path:=DbfXOpe.FieldByName('G1PATH').AsString;
      //ExPath:=DbfXOpe.FieldByName('IMPPATH').AsString;


  DbfBook0 := TDBF.Create(Nil);
  try
    DbfBook0.FilePath := 'k:\wc\f';
    DbfBook0.TableLevel := 3;
    DbfBook0.TableName := 'Libro0';
    DbfBook0.Exclusive := True;
    DbfBook0.Open;

    DbfBook0.First;
    while not DbfBook0.EOF do
      begin
        Ws1Name := DbfBook0.Fields[1].Value;

        Form1.WorkbookSource.Workbook.AddWorksheet(Ws1Name)
      end;
    DbfBook0.Close;

  finally

  end;
  DbfBook0.Free;
end;

end.
{

DbfG1_1 := TDBF.Create(Nil);
DbfG1_2 := TDBF.Create(Nil);
try
  DbfG1_1.FilePath := G1Path;
  DbfG1_1.TableLevel := 4;
  DbfG1_1.TableName := DocT;
  DbfG1_1.Exclusive := False;
  DbfG1_1.Open;

  FieldD2 := TDbfFieldDefs.Create(Nil);
  FieldD2.Assign(DbfG1_1.DbfFieldDefs);

  DbfG1_2.FilePath := ExPath;
  DbfG1_2.TableLevel := 3;
  DbfG1_2.TableName := 'G1_DOCT.DBF';
  DbfG1_2.Exclusive := False;

  DbfG1_2.CreateTableEx(FieldD2);
  DbfG1_2.Open;
  DbfG1_1.First;
  while not DbfG1_1.EOF do
    begin
      if LeftStr(DbfG1_1.FieldByName('TIPDOC').AsString,1) <> 'B' then
        begin
          Memo1.Append(' ' + DbfG1_1.FieldByName('TIPDOC').AsString + ' | ' + PadRight(DbfG1_1.FieldByName('ANNDOC').AsString,4) +' ' + PadRight(DbfG1_1.FieldByName('NUMDOC').AsString,6) + ' | ' + PadLeft(DbfG1_1.FieldByName('CODCF').AsString,6));
          DbfG1_2.Append;
          for i := 0 to DbfG1_1.FieldCount-1 do
            DbfG1_2.Fields[i].Value := DbfG1_1.Fields[i].Value;
          DbfG1_2.Post;
        end;
      DbfG1_1.next;
    end;
  FieldD2.Free;
  DbfG1_1.Close;
  DbfG1_2.Close;

  Memo0.Append('  Lettura Documenti Righe');

  DbfG1_1.TableName := DocR;
  DbfG1_1.Open;

  FieldD2 := TDbfFieldDefs.Create(Nil);
  FieldD2.Assign(DbfG1_1.DbfFieldDefs);

  DbfG1_2.TableName := 'G1_DOCR.DBF';
  DbfG1_2.CreateTableEx(FieldD2);
  DbfG1_2.Open;
  DbfG1_1.First;
  while not DbfG1_1.EOF do
    begin
      if LeftStr(DbfG1_1.FieldByName('TIPDOC').AsString,1) <> 'B' then
        begin
          Memo1.Append(' ' + DbfG1_1.FieldByName('TIPDOC').AsString + ' | ' + PadRight(DbfG1_1.FieldByName('ANNDOC').AsString,4) + ' ' + PadRight(DbfG1_1.FieldByName('NUMDOC').AsString,6) + ' ' + PadLeft(DbfG1_1.FieldByName('NUMRIG').AsString,6));
          DbfG1_2.Append;
          for i := 0 to DbfG1_1.FieldCount-1 do
            DbfG1_2.Fields[i].Value := DbfG1_1.Fields[i].Value;
          DbfG1_2.Post;
        end;
      DbfG1_1.next;
    end;
  FieldD2.Free;
  DbfG1_1.Close;
  DbfG1_2.Close;

except
   Memo0.Append(' ERRORE: Lettura Fallita')
end;

DbfG1_1.Free;
DbfG1_2.Free;

DbfXOpe.Edit;
DbfXOpe.Fields[3].Value := 'OK';
DbfXOpe.Post;

Form1.Close;
end;

}
end.

