Gracias Delphi.com.ar por tu ayuda, aca publico el còdigo que me mandaste un poco modificado:
Código:
procedure DataSetToStream(ADataSet: TDataSet; AStream: TStream);
var
i: Integer;
S: string;
begin
if not ADataSet.IsEmpty then
begin
S := '';
ADataSet.EnableControls;
try
for i := 0 to ADataSet.Fields.Count -1 do
begin
if (i = ADataSet.Fields.Count -1) then
S := S + ADataSet.fields[i].FieldName + #13#10
else
S := S + ADataSet.fields[i].FieldName + ';';
end;
AStream.Write(S[1], Length(S));
ADataSet.First;
repeat
S := '';
for i := 0 to ADataSet.Fields.Count -1 do
if ADataSet.Fields[i].Visible then
begin
if (i = ADataSet.Fields.Count -1) then
S := S + ADataSet.Fields[i].DisplayText + #13#10
else
S := S + ADataSet.Fields[i].DisplayText + ';';
end;
AStream.Write(S[1], Length(S));
ADataSet.Next;
until ADataSet.Eof;
finally
ADataSet.DisableControls;
end;
end;
end;
Con eso me salen las exportaciones con los nombres de las columnas. Le saquè el if que pregunta i > 0 porque no es necesario. Y en lugar del #9 le puse ; porque lo convierto a CSV.
Yanina Genia