PDA

View Full Version : ساخت فایل csv از طریق qurey



khoshblagh
پنج شنبه 19 دی 1392, 00:07 صبح
با سلام خدمت دوستان
میخواهم از یک کوئری یک فایل csv خروجی بگیرم. عبارت زیر از یک سایت بدست آوردم
ولی هندل نمودن آن مشکل دارم یعنی نمیدانم دقیقا چکار باید انجام بدهم.لطفا راهنمایی
بفرمائید. متشکرم.


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;

khoshblagh
پنج شنبه 19 دی 1392, 03:00 صبح
حل شد. متشکرم