使用 VSTO 创建新的 Word 文档
如何使用 Visual Studio Tools for Office 以编程方式创建新的 Word 文档?
How can I create a new Word document pro grammatically using Visual Studio Tools for Office?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您实际上追求的是使用 PIA(主互操作程序集)的办公自动化。
VSTO 实际上是一组托管 .net 扩展,它使编写 Office 加载项变得更加容易。 对于外部交互,根本不使用 VSTO(尽管您仍然可以引用 VSTO 库并根据需要使用一些帮助程序)。
请查看 http://support.microsoft.com/kb/316384 以开始使用。 并谷歌“word interop 创建文档”
What you are actually after is Office Automation using the PIA's (Primary Interop Assemblies).
VSTO is actually a set of Managed .net extensions which make writing add-ins for Office far easier. For external interaction VSTO is not used at all (though you can still reference VSTO libraries and use some of the helpers if you wanted to).
Have a look at http://support.microsoft.com/kb/316384 to get you started. And google 'word interop create document'
对于 VSTO 应用级加载项,您可以执行以下操作:
其中
objTemplate
可以是文档的模板请参阅 文档.添加方法
For a VSTO app-level add-in, you can do something like this:
where
objTemplate
can be a template of documentSee Documents.Add Method
现在,我在这一点上可能是错的,但我不相信您实际上可以使用 VSTO 制作新的 Word 文档。 我对 VSTO 不太熟悉,所以如果我在这一点上不正确,请原谅我。
不过,我确实知道您可以使用 Office Interop 库来执行此操作。
要下载这些库,只需搜索“office interop 程序集”,可能包括您想要的 Office 版本(例如:“office interop 程序集 2007”)。
将 Word Interop 程序集包含到应用程序中(使用“添加引用”)后,您可以执行以下操作:
希望有帮助!
Now, I might be wrong on this, but I don't believe you can actually make a new Word doc using VSTO. I'm not intimately familiar with VSTO, so forgive me if I'm incorrect on that point.
I do know that you can use Office Interop libraries to do this, however.
To download the libraries, just do a search for "office interop assemblies," possibly including the Office version you want (ex: "office interop assemblies 2007").
Once you've included the Word Interop assembly into your application (using Add Reference), you can do something like:
Hope that helps!