Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TransformaDadosDatasettoCsV(aFileName: string; aDataSet: TFDQuery);
- var
- myTextFile: TextFile;
- i: integer;
- s: string;
- function FileExists(aFileName:String):Boolean;
- var
- NomeArquivo: string;
- TXT: TextFile;
- begin
- NomeArquivo := aFileName;
- if not FileExists(NomeArquivo) then
- raise Exception.CreateFmt('O arquivo não existe!', [NomeArquivo]);
- AssignFile(TXT, NomeArquivo);
- Reset(TXT);
- try
- finally
- CloseFile(TXT);
- end;
- end;
- begin
- AssignFile(myTextFile, aFileName);
- Rewrite(myTextFile);
- s := '';
- try
- try
- for i := 0 to aDataSet.FieldCount - 1 do
- begin
- s := s + Format('"%s";', [aDataSet.Fields[i].FieldName]);
- end;
- Writeln(myTextFile, s);
- while not aDataSet.Eof do
- begin
- s := '';
- for i := 0 to aDataSet.FieldCount - 1 do
- begin
- s := s + Format('"%s";', [aDataSet.Fields[i].AsString]);
- end;
- Writeln(myTextfile, s);
- aDataSet.Next;
- end;
- finally
- CloseFile(myTextFile);
- end;
- Except
- on E: Exception do
- raise Exception.Create('Não foi possível realizar o processo de exportação.!');
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement