简体   繁体   English

带模板的Word 2010自动化

[英]Word 2010 automation with templates

I have written several applications in Delphi which use Word automation. 我已经在Delphi中编写了几个使用Word自动化的应用程序。 The programs all use templates which are stored in a directory. 这些程序都使用存储在目录中的模板。 In pre-2010 versions of Word, one would define the location of the templates in tools|options|file locations; 在2010之前的Word版本中,可以在tools | options | file位置中定义模板的位置。 the programs would pass the name of the template and Word would know where to find it. 程序将传递模板的名称,Word将知道在哪里可以找到它。

My client has now moved to Office 2010, and as a result, Word cannot find the template when started by my programs. 我的客户端现在已移至Office 2010,结果,Word由我的程序启动时找不到模板。 I haven't been able to find a similar dialog box in Word in which I can define the default directory for templates. 我在Word中找不到类似的对话框,无法在其中定义模板的默认目录。 How does one define such a directory? 如何定义这样的目录?

Click File | 单击文件| Options | 选项| Advanced | 进阶| File Locations and you get the same dialog as in older verions 文件位置,您将获得与旧版本相同的对话框 替代文字

Instead of forcing your user to configure Word to define the location of templates, you might prefer to invoke word using /t switch. 与其强迫用户配置Word以定义模板的位置,不如使用/ t开关来调用word。

/ttemplatename starts Word with a new document based on a template other than the Normal template. / ttemplatename以基于普通模板以外的模板的新文档启动Word。

>"%programfiles%\Microsoft Office\Office14\winword.exe" /t"c:\MYTEMPLATES\mytemplate.dotx"

Can't you just specify the full path when creating a new document? 创建新文档时,您是否只能指定完整路径? Why rely on a settings that possibly can even be changed by the user? 为什么要依靠用户甚至可以更改的设置? Put your templates in your own folder and specify the full path. 将模板放在您自己的文件夹中,并指定完整路径。

Word's paths configuration are stored Word的路径配置已存储

You can get the USER template folder via 您可以通过以下方式获得USER模板文件夹

Word.Application.Options.DefaultFilePath(WdDefaultFilePath.wdUserTemplatesPath) Word.Application.Options.DefaultFilePath(WdDefaultFilePath.wdUserTemplatesPath)

(there are others options for that property too). (该属性还有其他选择)。

As far as I can tell, the template loading rules haven't changed from 2007 to 2010. 据我所知,模板加载规则从2007年到2010年没有变化。

Generally speaking, if your add in needs to load a template, you should specify the FULL path and file name to the template, but you can get the typical user path via the above. 一般来说,如果您的加载项需要加载模板,则应为模板指定FULL路径和文件名,但是您可以通过上述方法获得典型的用户路径。

On the other hand, if you install the template into WORD\\STARTUP, word will automatically load it. 另一方面,如果将模板安装到WORD \\ STARTUP中,则word将自动加载它。 that may not be what you need/want, though. 不过,这可能不是您需要/想要的。

Finally, if your template doesn't/shouldn't change, it might be better to leave it in your PROGRAM FILES\\appname folder and load it from there. 最后,如果您的模板没有/不应更改,则最好将其保留在PROGRAM FILES \\ appname文件夹中,然后从那里加载它。

Generally speaking, +requiring+ users to change the FILE LOCATIONS in word (or changing it programmatically) is a bad idea, just because so many people wouldn't have a clue, and those that do definitely DO NOT want addins changing those settings automatically! 一般来说,+要求+用户更改Word中的文件位置(或以编程方式进行更改)是一个坏主意,因为这么多的人没有头绪,而那些确实想知道的人不希望插件自动更改这些设置!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM