将Word文档加载到OleContainer时,请求的对象不存在(0x80010114)
我通过自动化创建了一个 Word 文档(启动 Word、打开模板、将其保存到 .doc、关闭文档、退出 Word)。之后,我想在 TOleContainer 中打开此 .doc 文件:fOleContainer.CreateObjectFromFile(lTempFileName, False);
。
但是我们的一个使用 Word 2010(多台计算机、Windows 7 / Windows XP)的客户在该行上收到错误:请求的对象不存在 (0x80010114)。
是什么导致了这个错误?我该如何解决这个问题?
代码:
procedure CreateNewWordDocument(const aFile, aTemplate: string);
var
lApp: WordApplication;
lDocuments: Documents;
lDoc: WordDocument;
lFileName: OleVariant;
lTemplate: OleVariant;
begin
lApp := CoWordApplication.Create;
lDocuments := lApp.Documents;
if aTemplate = '' then
lDoc := lDocuments.AddOld(EmptyParam, olFalse)
else
begin
lFileName := aTemplate;
lDoc := lDocuments.AddOld(lFileName, olFalse);
end;
lDocuments := nil;
lFileName := aFile;
lTemplate := lDoc.Get_AttachedTemplate;
lTemplate.Saved := True;
lTemplate := lApp.NormalTemplate;
lTemplate.Saved := True;
lTemplate := Null;
lDoc.SaveAs2000(lFileName, olwdFormatDocument, EmptyParam, EmptyParam, olFalse,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
lDoc.Close(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
lDoc := nil;
lApp.Quit(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
lApp := nil;
end;
...
CreateNewWordDocument('c:\windows\temp\~tmp2343.tmp.doc', 'c:\mytemplate.dot');
fOleContainer.CreateObjectFromFile(lTempFileName);
I created a Word document through automation (Start Word, Open template, Saved it to .doc, Close document, Quit Word). After that I want to open this .doc-file in an TOleContainer: fOleContainer.CreateObjectFromFile(lTempFileName, False);
.
But a client of ours who uses Word 2010 (several machines, Windows 7 / Windows XP) gets an error on that line: The requested object does not exist (0x80010114).
What is causing this error and how can I solve this?
Code:
procedure CreateNewWordDocument(const aFile, aTemplate: string);
var
lApp: WordApplication;
lDocuments: Documents;
lDoc: WordDocument;
lFileName: OleVariant;
lTemplate: OleVariant;
begin
lApp := CoWordApplication.Create;
lDocuments := lApp.Documents;
if aTemplate = '' then
lDoc := lDocuments.AddOld(EmptyParam, olFalse)
else
begin
lFileName := aTemplate;
lDoc := lDocuments.AddOld(lFileName, olFalse);
end;
lDocuments := nil;
lFileName := aFile;
lTemplate := lDoc.Get_AttachedTemplate;
lTemplate.Saved := True;
lTemplate := lApp.NormalTemplate;
lTemplate.Saved := True;
lTemplate := Null;
lDoc.SaveAs2000(lFileName, olwdFormatDocument, EmptyParam, EmptyParam, olFalse,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
lDoc.Close(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
lDoc := nil;
lApp.Quit(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
lApp := nil;
end;
...
CreateNewWordDocument('c:\windows\temp\~tmp2343.tmp.doc', 'c:\mytemplate.dot');
fOleContainer.CreateObjectFromFile(lTempFileName);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论