如何调用系统的word程序?如:怎么才能打开一个word文件?
要用到WordDocument或者WordApplication组件?如果用,怎么用??
要用到WordDocument或者WordApplication组件?如果用,怎么用??
解决方案 »
- webbrowser递归遍历网页元素问题求教!
- Tmyclass = class(TObject) 好像不用实例化就能用啊
- 急急急.......!求ImageEnView的SetViewXY(x, y: integer)函数中的两个参数具体含义
- 如何模拟delphi弹出式菜单操作
- idTCPServer 挂起问题?
- 如何清除字符串的标点?
- 我的机器上装了mdac 2.6版本,原来用2.1ado写的程序用不了,怎么从2.6转到2.1
- 请问哪里可以下载delphi 6.0?
- 运行提示TjpegImage等未声明,如何声明?
- Delphi使ListBox下拉时出现水平滚动条?
- 请帮忙找一下错误在哪。 谢谢。。。。。
- 高手请进---一个蹊跷的问题
启动Word时用如下代码:
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
end;关闭Word用如下代码。如果想保存Doc文件,请修改SaveChanges变量的内容:
var
SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
SaveChanges := WdDoNotSaveChanges;
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned;
try
WordApplication.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication.Disconnect;
except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;让Word打开一个指定的文件,需要先放置OpenDialog,然后调用WordApplication.Documents.Open:
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
if not dlgOpen.Execute then
Exit;{Open document}
FileName := dlgOpen.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );{Assign WordDocument component}
ItemIndex := 1;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;让Word替换标记字符串要使用WordDocument.Range.Find.Execute,这里用Delphi替换了<#Name>:
var
FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace: OleVariant;
begin
FindText := '<#Name>';
MatchCase := False;
MatchWholeWord := True;
MatchWildcards := False;
MatchSoundsLike := False;
MatchAllWordForms := False;
Forward := True;
Wrap := wdFindContinue;
Format := False;
ReplaceWith := 'Delphi';
Replace := True;WordDocument.Range.Find.Execute( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward,
Wrap, Format, ReplaceWith, Replace );
rongercao (2001-6-8 2:25:00)
uses comobj;
var msword:variant;
msword:=createobject('word.application');
msword.documents.open(要打开的文件);
msword.visible:=1;
如果要断开word与服务器的连接
msword:=unassigned