use
Word2000, OleServer,ComObj;
procedure TForm_feecode.Panel2Click(Sender: TObject);
var
WordApp,WordDoc,WordTable:OleVariant;
i,j:integer;
begin
if MessageDlg('请确定你已经安装了WORD?', mtInformation, [mbOK,mbCancel],0)=mrOK then
begin
if adoquery1.Active=true then
begin
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
Wordapp.options.checkSpellingAsYouType:=false;
Wordapp.options.CheckGrammarAsyouType:=false;
WordTable:=WordDoc.Tables.Add(WordApp.Selection.Range,DBGrid1.DataSource.DataSet.RecordCount+1,DBGrid1.Columns.Count);
for i:=1 to DBGrid1.Columns.Count do
WordTable.Cell(1,i).Range.InsertAfter(DBGrid1.Columns[i-1].Title.Caption);
i:=2;
while ADOquery1.Eof=false do
begin
for j:=1 to ADOquery1.FieldCount do
WordTable.Cell(i,j).Range.InsertAfter(ADOquery1.Fields.Fields[j-1].AsString);
ADOquery1.Next;
Inc(i);
end;
end
else
application.MessageBox ('请先查询再导出数据','Error', MB_OK);
end
可能是答非所问,看看总有帮助。