[Crystal Studio Web] [DELPHI] TQuery results to the word of: chinawzw Recommended: chinawzw ------------------------------ -------------------------------------------------- unit ExcelTest; interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, db, dBTables, ComCtrls; typeTForm1 = class (TForm) Button1: TButton; Query1: TQuery; procedure Button1Click (Sender: TObject); private {Private declarations} public {public declarations} procedure WriteDatasetToExcel (AQueryName: TQuery; AStrVar: String); end; varForm1: TForm1; implementationuses Comobj; {$ R * .DFM} {TForm1} procedure TForm1.WriteDatasetToExcel (AQueryName : TQuery; astrvar: string; VareClapp, Workbook: Variant; Range, WordApp: variant; xlsfilename: string; ie: integer; column: integer; row: integer; fdate: tdatetime; year, month, day, hour, min, SEC, MSEC: Word; strdate: string; strdate1: string; beginwordapp: = createoleObject ('word.application'); Wordapp.Visible: = true; wordapp.documents.add; = wordapp.documents.ite: = wordapp.documents.ite m (1) .range; // This is written in Range.Text: = 'this is a; Aklsdjfkljasd'; // This is saved {WordApp.Documents.Item (1) .saves ('c: /foo.doc) '); Word.Options.sendmailattach: = true; Wordapp.Documents.Item (1) .sendmail;} // This is exiting Wordapp.Documents.Item (1) .close; Wordapp.quit; end; procedure tForm1.button1click (Sender: TOBJECT); BeginWriteDataSetToExcel (Query1, 'Excel file test'); end; end.