我通过自动化创建了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);