Por supuesto que sí.
Simplemente tiene que hacer el trabajo para generar correctamente el contenido CSV (cotizando correctamente, manejando comillas y comas incrustadas, etc.). Puede escribir fácilmente la salida usando TFileStream
, y obtener los datos usando TQuery.Fields
y TQuery.FieldCount
correctamente.
Dejaré las citas de lujo de CSV y el manejo especial para usted. Esto se hará cargo de la parte fácil:
var
Stream: TFileStream;
i: Integer;
OutLine: string;
sTemp: string;
begin
Stream := TFileStream.Create('C:\Data\YourFile.csv', fmCreate);
try
while not Query1.Eof do
begin
// You'll need to add your special handling here where OutLine is built
OutLine := '';
for i := 0 to Query.FieldCount - 1 do
begin
sTemp := Query.Fields[i].AsString;
// Special handling to sTemp here
OutLine := OutLine + sTemp + ',';
end;
// Remove final unnecessary ','
SetLength(OutLine, Length(OutLine) - 1);
// Write line to file
Stream.Write(OutLine[1], Length(OutLine) * SizeOf(Char));
// Write line ending
Stream.Write(sLineBreak, Length(sLineBreak));
Query1.Next;
end;
finally
Stream.Free; // Saves the file
end;
end;
Es bastante simple escribir un emisor de archivos CSV. Dado que no puede encontrar la funcionalidad integrada, y dado que no desea soluciones de terceros, entonces es probable que deba seguir esta ruta. –
ya que estamos hablando de CSV hay un buen artículo sobre patrones de diseño el uso de un analizador CSV como ejemplo- http://conferences.embarcadero.com/article/32129 – Najem