如何在Delphi中显示和存取Word文档之急上加
展开全部
这是我自己用的模块,用来显示存储WORD文件,不过要安装WORD才能正确运行!
//********************//
procedure TForm3.Button1Click(Sender: TObject);
var MSWord:Variant;
i,j:Integer;
begin
SaveDialog1.Filter:='*.DOC|*.DOC';
SaveDialog1.DefaultExt:='DOC';
if SaveDialog1.Execute then
begin
MSWord:=CreateOLEObject('Word.Application');
MSWord.Documents.Open(FileName:=SaveDialog1.FileName,ReadOnly:=False);
MSWord.Visible:=False;
MSWord.ActiveDocument.Range(Start:=0,End:=0);
Table1.Open;
j:=Table1.RecordCount;
Table1.First;
for i:=1 to j do
begin
MSWord.ActiveDocument.Range.InsertAfter(Text:=Table1.FieldByName('CODE').AsString+Table1.FieldByName('COLOR').AsString+Chr(13));
Table1.Next;
end;
MSWord.Documents.Close;
end;
end;
//********************//
procedure TForm3.Button1Click(Sender: TObject);
var MSWord:Variant;
i,j:Integer;
begin
SaveDialog1.Filter:='*.DOC|*.DOC';
SaveDialog1.DefaultExt:='DOC';
if SaveDialog1.Execute then
begin
MSWord:=CreateOLEObject('Word.Application');
MSWord.Documents.Open(FileName:=SaveDialog1.FileName,ReadOnly:=False);
MSWord.Visible:=False;
MSWord.ActiveDocument.Range(Start:=0,End:=0);
Table1.Open;
j:=Table1.RecordCount;
Table1.First;
for i:=1 to j do
begin
MSWord.ActiveDocument.Range.InsertAfter(Text:=Table1.FieldByName('CODE').AsString+Table1.FieldByName('COLOR').AsString+Chr(13));
Table1.Next;
end;
MSWord.Documents.Close;
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |