W
wpgl1
Unregistered / Unconfirmed
GUEST, unregistred user!
调用WORD打开一个文件后,呆一会不做任何WORD操作,然后在打开,程序报错:“文档名或路径无效”。把WORD关掉在打开就好了,然后在呆一会,问题依旧。
还有一种情况,打开一个文件后,如果改动文件内容,然后重新回到程序,在打开WORD,程序报错,问题如上。请各位高手指点!
程序如下:
--------
procedure Tmain.Button1Click(Sender: TObject);
var
itemindex levariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format,
Template,NewTemplate,savechanges,routedocument: olevariant;
begin
if tablelist.Columns.Grid.Fields[0].Text<>'' then begin
try
Template := EmptyParam;
NewTemplate := True;
try
Wordapp.Connect;
except
MessageDlg('请安装WORD!', mtError, [mbOk], 0);
Abort;
end;
Wordapp.Visible := True;
WordApp.Caption := '丛书检索.....';
//////////////////////////
filename:='';
filename :='./doc/'+tablelist.Columns.Grid.Fields[1].Text+'.doc';
label2.Caption :=filename;
confirmconversions := false;
readonly := false;
addtorecentfiles := false;
passworddocument := '';
passwordtemplate := '';
revert := true;
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument;
wordapp.documents.open( filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format );
itemindex :=1;
worddoc.connectto(wordapp.documents.item(itemindex));
{turn spell checking of because it takes a long time if enabled and slows down winword}
wordapp.options.checkspellingasyoutype := false;
wordapp.options.checkgrammarasyoutype := false;
wordapp.Selection.WholeStory;
wordapp.Selection.Copy;
worddoc.Close;
{Create new document}
Template := EmptyParam;
NewTemplate := False;
WordApp.Documents.Add(Template, NewTemplate);
// {Assign WordDocument component}
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
wordapp.Selection.Paste;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApp.Disconnect;
end;
end;
end;
还有一种情况,打开一个文件后,如果改动文件内容,然后重新回到程序,在打开WORD,程序报错,问题如上。请各位高手指点!
程序如下:
--------
procedure Tmain.Button1Click(Sender: TObject);
var
itemindex levariant;
filename, confirmconversions, readonly, addtorecentfiles,
passworddocument, passwordtemplate, revert,
writepassworddocument, writepasswordtemplate, format,
Template,NewTemplate,savechanges,routedocument: olevariant;
begin
if tablelist.Columns.Grid.Fields[0].Text<>'' then begin
try
Template := EmptyParam;
NewTemplate := True;
try
Wordapp.Connect;
except
MessageDlg('请安装WORD!', mtError, [mbOk], 0);
Abort;
end;
Wordapp.Visible := True;
WordApp.Caption := '丛书检索.....';
//////////////////////////
filename:='';
filename :='./doc/'+tablelist.Columns.Grid.Fields[1].Text+'.doc';
label2.Caption :=filename;
confirmconversions := false;
readonly := false;
addtorecentfiles := false;
passworddocument := '';
passwordtemplate := '';
revert := true;
writepassworddocument := '';
writepasswordtemplate := '';
format := wdopenformatdocument;
wordapp.documents.open( filename, confirmconversions,
readonly, addtorecentfiles, passworddocument, passwordtemplate,
revert, writepassworddocument, writepasswordtemplate, format );
itemindex :=1;
worddoc.connectto(wordapp.documents.item(itemindex));
{turn spell checking of because it takes a long time if enabled and slows down winword}
wordapp.options.checkspellingasyoutype := false;
wordapp.options.checkgrammarasyoutype := false;
wordapp.Selection.WholeStory;
wordapp.Selection.Copy;
worddoc.Close;
{Create new document}
Template := EmptyParam;
NewTemplate := False;
WordApp.Documents.Add(Template, NewTemplate);
// {Assign WordDocument component}
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
wordapp.Selection.Paste;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApp.Disconnect;
end;
end;
end;