R
rocsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用DELPHI调用WORD,打开一个文件,编辑后,点击一个按钮,将该文件保存到数据库。现在出现的问题是,程序启动后第一次启动WORD,使用没有任何问题,再次启动WORD则出现class EOleSysError of message‘被呼叫方拒绝接收呼叫’的错误。我想可能是WORD关闭造成的,因为重新启动程序后,再启动WORD又好了,第二次调用又是一样的错误。
后面是代码,请各位帮忙看看!
//启动WORD模板进行处理
try
confirmconversions:= false;
readonly:= true;
addtorecentfiles:= false;
passworddocument:= '';
passwordtemplate:= '';
revert:= true;
writepassworddocument:= '';
writepasswordtemplate:= '';
format:= wdopenformatdocument;
encoding:='';
visible:=true;
wordapplication.Documents.Open(filename,confirmconversions,readonly,addtorecentfiles, passworddocument,passwordtemplate,revert,writepassworddocument,writepasswordtemplate,format,encoding,visible);
{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;
wordapplication.connect;
except
messagedlg('可能没有安装好WORD', mterror, [mbok], 0);
abort;
end;
wordapplication.visible := true;
......处理WORD文件.........
下面是保存到数据库的代码:
begin
filename:='c:/temp/temp1.doc';
fileformat:=wdformatdocument;
addtorecentfile:=false;
worddocument.SaveAs(filename,fileformat,addtorecentfile);
//worddocument.Close;
//worddocument.Disconnect;
wordapplication.Quit;
wordapplication.Disconnect;
str:=tmemorystream.Create;
str.LoadFromFile(filename);
str.Position:=0;
tidentifypaper.Close;
tidentifypaper.Open;
if tidentifypaper.Locate('identifypaperno',paperno,[]) then
begin
tidentifypaper.Edit;
tblobfield(tidentifypaper.FieldByName('doc')).LoadFromStream(str);
try
tidentifypaper.Post;
tidentifypaper.Close;
saveornot:=true;
showmessage('保存成功!');
finally
str.Free;
deletefile(filename);
tidentifypaper.Close
end;
end;
end;
后面是代码,请各位帮忙看看!
//启动WORD模板进行处理
try
confirmconversions:= false;
readonly:= true;
addtorecentfiles:= false;
passworddocument:= '';
passwordtemplate:= '';
revert:= true;
writepassworddocument:= '';
writepasswordtemplate:= '';
format:= wdopenformatdocument;
encoding:='';
visible:=true;
wordapplication.Documents.Open(filename,confirmconversions,readonly,addtorecentfiles, passworddocument,passwordtemplate,revert,writepassworddocument,writepasswordtemplate,format,encoding,visible);
{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;
wordapplication.connect;
except
messagedlg('可能没有安装好WORD', mterror, [mbok], 0);
abort;
end;
wordapplication.visible := true;
......处理WORD文件.........
下面是保存到数据库的代码:
begin
filename:='c:/temp/temp1.doc';
fileformat:=wdformatdocument;
addtorecentfile:=false;
worddocument.SaveAs(filename,fileformat,addtorecentfile);
//worddocument.Close;
//worddocument.Disconnect;
wordapplication.Quit;
wordapplication.Disconnect;
str:=tmemorystream.Create;
str.LoadFromFile(filename);
str.Position:=0;
tidentifypaper.Close;
tidentifypaper.Open;
if tidentifypaper.Locate('identifypaperno',paperno,[]) then
begin
tidentifypaper.Edit;
tblobfield(tidentifypaper.FieldByName('doc')).LoadFromStream(str);
try
tidentifypaper.Post;
tidentifypaper.Close;
saveornot:=true;
showmessage('保存成功!');
finally
str.Free;
deletefile(filename);
tidentifypaper.Close
end;
end;
end;