delphi内如何嵌入打开WORD,看网上是添加OleContainer控件,但不知道如何写代码能让文档在此控件中打开
1个回答
展开全部
Delphi中利于 RIchEdit 阅读 WORD内容:
.....
procedure TForm1.Button1Click(Sender: TObject);
var
fnm: String;
WordApp,WordDoc: Variant;
sContext: String;
begin
if OpenDialog1.Execute then begin
fnm := OpenDialog1.FileName;
Label2.Caption := fnm;
WordApp := CreateOleObject('Word.Application');
try
WordApp.Visible := False;
WordDoc := WordApp.Documents.Open(fnm);
WordApp.Selection.WholeStory;
sContext := WordDoc.Range.Text;
RichEdit1.Text := sContext;
finally
WordApp.Quit;
end;
end;
end;
.....
procedure TForm1.Button1Click(Sender: TObject);
var
fnm: String;
WordApp,WordDoc: Variant;
sContext: String;
begin
if OpenDialog1.Execute then begin
fnm := OpenDialog1.FileName;
Label2.Caption := fnm;
WordApp := CreateOleObject('Word.Application');
try
WordApp.Visible := False;
WordDoc := WordApp.Documents.Open(fnm);
WordApp.Selection.WholeStory;
sContext := WordDoc.Range.Text;
RichEdit1.Text := sContext;
finally
WordApp.Quit;
end;
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询