我需要能够打开和编辑Delphi中的Word模板(使用Word) 我可以打开模板,但是Word会假定它是文档而不是模板。打开并编辑Delphi中的Word模板
问题是我需要编辑模板而不是将它用作新文档的模板。 我使用模板作为文档处理系统的一部分,我希望用户能够从我的应用编辑模板。现在,他们必须打开Word,然后从那里打开模板并对其进行编辑 - 从我的应用程序执行该模板会更容易,更安全。
实验代码
fWordApp: WordApplication;
TempName: OleVariant;
WordDoc: WordDocument;
TemplateFile: string;
begin
TemplateFile := Settings.Directories.RootInsert(qryTemplates.FieldByName('fldtemplate_path').AsString);
if TemplateFile <> '' then
begin
if not Assigned(fWordApp) then
begin
fWordApp := CreateOleObject('Word.Application') as WordApplication;
while fWordApp.Templates.Count = 0 do
Sleep(200); // Normal.dot must be loaded
end;
if Assigned(fWordApp) then
fWordApp.Visible := True
else
raise Exception.Create('Cannot initialize Word application');
TempName := TemplateFile;
WordDoc := fWordApp.Documents.Add(TempName, EmptyParam, wdFormatTemplate, EmptyParam);
我不明白。你能否详细说明,最好是用代码。 –
Word模板也是Word文档。差异只是扩展,因此与Word/Shell不同的行为 - 双击模板文件将创建一个基于模板的新文档 –