csv文件的生成

procedure TForm5.Button2Click(Sender: TObject);
var
  Stream: TFileStream;
  i: Integer;
  OutLine: string;
  sTemp: string;
begin
  showmessage('下载商品信息表成功,默认路径为E盘');
  Stream := TFileStream.Create('E:\itemorder.csv', fmCreate);
  try
    while not ADOQuery1.Eof do
    begin
      // You'll need to add your special handling here where OutLine is built
      OutLine := '';
      for i := 0 to ADOQuery1.FieldCount - 1 do
      begin
        sTemp := ADOQuery1.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));
       ADOQuery1.Next;
    end;
  finally
    Stream.Free;  // Saves the file
  end;
end;

你可能感兴趣的:(Delphi专栏)