高手指点!看看我的程序,帮我解决一下word的问题(50分)

  • 主题发起人 主题发起人 aijiaxin
  • 开始时间 开始时间
A

aijiaxin

Unregistered / Unconfirmed
GUEST, unregistred user!
我的问题是:数据库中的数据输入到word中,下面的代码可以实现,但是下面的只能显示一条数据
我想把所有的数据都要输入到word中,怎么办?高手指点一下啊


下面是的我源代码:

var
MemoStream:TMemoryStream;
Blob:TStream;
begin
if ADOQuery1.FieldByName('内容').IsNull then
begin
Exit;
end;
Screen.Cursor := crHourGlass;
MemoStream := TMemoryStream.Create;
try
MemoStream.Seek(0,soFromBeginning);
Blob := ADOQuery1.CreateBlobStream(ADOQuery1.FieldByName('内容'),bmRead);
try
Blob.Seek(0,soFromBeginning);
MemoStream.CopyFrom(Blob,Blob.Size);
MemoStream.SaveToFile('c:/test.rtf');
finally
Blob.Free;
end;
finally
MemoStream.Free;
Screen.Cursor:=crDefault;
end;

end;
 
var
MemoStream:TMemoryStream;
Blob:TStream;
myword:variant;
begin
try
MyWord := CreateOleObject('Word.Application');
except
ShowMessage('请您安装Word97及以上版本的Microsoft Word程序!');
Screen.Cursor := crDefault;
Exit;
end;
MyWord.documents.add;//创建一个新文档

adoquery1.first;
while not ADOQuery1.eof do
begin
if ADOQuery1.FieldByName('内容').IsNull then
begin
Exit;
end;
Screen.Cursor := crHourGlass;
MemoStream := TMemoryStream.Create;
try
MemoStream.Seek(0,soFromBeginning);
Blob := ADOQuery1.CreateBlobStream(ADOQuery1.FieldByName('内容'),bmRead);
try
Blob.Seek(0,soFromBeginning);
MemoStream.CopyFrom(Blob,Blob.Size);
MemoStream.SaveToFile('c:/test.rtf');
MyWord.Selection.EndKey (Unit:=wdLine);
MyWord.Selection.InsertFile('c:/test.rtf', '', False, false, false);
finally
Blob.Free;
end;
finally
MemoStream.Free;
Screen.Cursor:=crDefault;
end;
adoquery1.next;
end;
 
谢谢myid0602,我去运行一下
 
接受答案了.
 
后退
顶部