Delphi Query1 导出csv txt


本文整理自网络,侵删。

 
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 ',' delphitop.com
      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;

相关阅读 >>

Delphi android路径 tpath 文件路径,文件管理

Delphi数组之菜鸟篇

Delphi 使用 {$include} 或 {$i} 指令管理和调用自定义函数

Delphi 控制鼠标按坐标点击

Delphi 通过memorystream 传递image1数据

Delphi 实现窗口记住关闭时的坐标位置

Delphi idhashmessagedigest, idhash, idglobal md5

Delphi根据进程pid等待进程结束或者结束进程

Delphi 判断文件是否存在

Delphi 内存管理[5]

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...